11import uuid
22import time
3+ from typing import Optional
34from pydantic import BaseModel
45
56from src .resources .database .entity import Database
@@ -11,22 +12,19 @@ def __init__(self,
1112 analysis_id : str ,
1213 pipeline_name : str ,
1314 run_args : list [str ],
14- run_id : Optional [str ],
15- database : Optional [Database ]) -> None :
16- if database is not None :
17- self .run_id = f"nf-run-{ uuid .uuid4 ()} "
18- self .analysis_id = analysis_id
19- self .pipeline_name = pipeline_name
20- self .run_args = run_args
21- else :
22- self .run_id = run_id
23- nf_run = database .get_nf_run_by_run_id (run_id )
24- self .analysis_id = nf_run .analysis_id
25- self .pipeline_name = nf_run .pipeline_name
26- self .run_args = nf_run .run_args
15+ run_id : Optional [str ] = None ) -> None :
16+ self .run_id = f"nf-run-{ uuid .uuid4 ()} " if run_id is None else run_id
17+ self .analysis_id = analysis_id
18+ self .pipeline_name = pipeline_name
19+ self .run_args = run_args
2720 self .time_created : float = time .time ()
2821 self .time_updated : float = time .time ()
2922
23+ @classmethod
24+ def from_database (cls , run_id : str , database : Database ) -> 'NextflowRunEntity' :
25+ nf_run = database .get_nf_run_by_run_id (run_id )
26+ return cls (nf_run .analysis_id , nf_run .pipeline_name , nf_run .run_args , run_id = run_id )
27+
3028 def start (self , database : Database ) -> None :
3129 database .create_nf_run (self .run_id , self .analysis_id )
3230 # TODO: Retrieve data from StorageClient
0 commit comments