@@ -95,7 +95,7 @@ async def _init(self, db_conf: DBConfiguration, create_triggers=DB_TRIGGER_CREAT
9595
9696 break # Break the retry loop
9797 except Exception as e :
98- self .logger .exception ("Exception occured " )
98+ self .logger .exception ("Exception occurred " )
9999 if retries - i <= 1 :
100100 raise e
101101 time .sleep (connection_retry_wait_time_seconds )
@@ -466,6 +466,10 @@ class AsyncFlowTablePostgres(AsyncPostgresTable):
466466 )
467467 _row_type = FlowRow
468468
469+ @staticmethod
470+ def get_filter_dict (flow_id : str ):
471+ return {"flow_id" : flow_id }
472+
469473 async def add_flow (self , flow : FlowRow ):
470474 dict = {
471475 "flow_id" : flow .flow_id ,
@@ -476,7 +480,7 @@ async def add_flow(self, flow: FlowRow):
476480 return await self .create_record (dict )
477481
478482 async def get_flow (self , flow_id : str ):
479- filter_dict = { " flow_id" : flow_id }
483+ filter_dict = self . get_filter_dict ( flow_id )
480484 return await self .get_records (filter_dict = filter_dict , fetch_single = True )
481485
482486 async def get_all_flows (self ):
@@ -523,9 +527,13 @@ async def add_run(self, run: RunRow):
523527 }
524528 return await self .create_record (dict )
525529
526- async def get_run (self , flow_id : str , run_id : str , expanded : bool = False ):
530+ @staticmethod
531+ def get_filter_dict (flow_id : str , run_id : str ):
527532 key , value = translate_run_key (run_id )
528- filter_dict = {"flow_id" : flow_id , key : str (value )}
533+ return {"flow_id" : flow_id , key : str (value )}
534+
535+ async def get_run (self , flow_id : str , run_id : str , expanded : bool = False ):
536+ filter_dict = self .get_filter_dict (flow_id , run_id )
529537 return await self .get_records (filter_dict = filter_dict ,
530538 fetch_single = True , expanded = expanded )
531539
@@ -534,9 +542,7 @@ async def get_all_runs(self, flow_id: str):
534542 return await self .get_records (filter_dict = filter_dict )
535543
536544 async def update_heartbeat (self , flow_id : str , run_id : str ):
537- run_key , run_value = translate_run_key (run_id )
538- filter_dict = {"flow_id" : flow_id ,
539- run_key : str (run_value )}
545+ filter_dict = self .get_filter_dict (flow_id , run_id )
540546 set_dict = {
541547 "last_heartbeat_ts" : int (datetime .datetime .utcnow ().timestamp ())
542548 }
@@ -589,19 +595,23 @@ async def add_step(self, step_object: StepRow):
589595 }
590596 return await self .create_record (dict )
591597
598+ @staticmethod
599+ def get_filter_dict (flow_id : str , run_id : str , step_name : str ):
600+ run_id_key , run_id_value = translate_run_key (run_id )
601+ return {
602+ "flow_id" : flow_id ,
603+ run_id_key : run_id_value ,
604+ "step_name" : step_name ,
605+ }
606+
592607 async def get_steps (self , flow_id : str , run_id : str ):
593608 run_id_key , run_id_value = translate_run_key (run_id )
594609 filter_dict = {"flow_id" : flow_id ,
595610 run_id_key : run_id_value }
596611 return await self .get_records (filter_dict = filter_dict )
597612
598613 async def get_step (self , flow_id : str , run_id : str , step_name : str ):
599- run_id_key , run_id_value = translate_run_key (run_id )
600- filter_dict = {
601- "flow_id" : flow_id ,
602- run_id_key : run_id_value ,
603- "step_name" : step_name ,
604- }
614+ filter_dict = self .get_filter_dict (flow_id , run_id , step_name )
605615 return await self .get_records (filter_dict = filter_dict , fetch_single = True )
606616
607617
@@ -651,36 +661,35 @@ async def add_task(self, task: TaskRow):
651661 }
652662 return await self .create_record (dict )
653663
654- async def get_tasks (self , flow_id : str , run_id : str , step_name : str ):
664+ @staticmethod
665+ def get_filter_dict (flow_id : str , run_id : str , step_name : str , task_id : str ):
655666 run_id_key , run_id_value = translate_run_key (run_id )
656- filter_dict = {
667+ task_id_key , task_id_value = translate_task_key (task_id )
668+ return {
657669 "flow_id" : flow_id ,
658670 run_id_key : run_id_value ,
659671 "step_name" : step_name ,
672+ task_id_key : task_id_value ,
660673 }
661- return await self .get_records (filter_dict = filter_dict )
662674
663- async def get_task (self , flow_id : str , run_id : str , step_name : str ,
664- task_id : str , expanded : bool = False ):
675+ async def get_tasks (self , flow_id : str , run_id : str , step_name : str ):
665676 run_id_key , run_id_value = translate_run_key (run_id )
666- task_id_key , task_id_value = translate_task_key (task_id )
667677 filter_dict = {
668678 "flow_id" : flow_id ,
669679 run_id_key : run_id_value ,
670680 "step_name" : step_name ,
671- task_id_key : task_id_value ,
672681 }
682+ return await self .get_records (filter_dict = filter_dict )
683+
684+ async def get_task (self , flow_id : str , run_id : str , step_name : str ,
685+ task_id : str , expanded : bool = False ):
686+ filter_dict = self .get_filter_dict (flow_id , run_id , step_name , task_id )
673687 return await self .get_records (filter_dict = filter_dict ,
674688 fetch_single = True , expanded = expanded )
675689
676690 async def update_heartbeat (self , flow_id : str , run_id : str , step_name : str ,
677691 task_id : str ):
678- run_key , run_value = translate_run_key (run_id )
679- task_key , task_value = translate_task_key (task_id )
680- filter_dict = {"flow_id" : flow_id ,
681- run_key : str (run_value ),
682- "step_name" : step_name ,
683- task_key : str (task_value )}
692+ filter_dict = self .get_filter_dict (flow_id , run_id , step_name , task_id )
684693 set_dict = {
685694 "last_heartbeat_ts" : int (datetime .datetime .utcnow ().timestamp ())
686695 }
@@ -757,23 +766,27 @@ async def add_metadata(
757766 }
758767 return await self .create_record (dict )
759768
769+ @staticmethod
770+ def get_filter_dict (flow_id : str , run_id : str , step_name : str , task_id : str ):
771+ run_id_key , run_id_value = translate_run_key (run_id )
772+ task_id_key , task_id_value = translate_task_key (task_id )
773+ return {
774+ "flow_id" : flow_id ,
775+ run_id_key : run_id_value ,
776+ "step_name" : step_name ,
777+ task_id_key : task_id_value ,
778+ }
779+
760780 async def get_metadata_in_runs (self , flow_id : str , run_id : str ):
761781 run_id_key , run_id_value = translate_run_key (run_id )
762782 filter_dict = {"flow_id" : flow_id ,
763783 run_id_key : run_id_value }
764784 return await self .get_records (filter_dict = filter_dict )
765785
766786 async def get_metadata (
767- self , flow_id : str , run_id : int , step_name : str , task_id : str
787+ self , flow_id : str , run_id : str , step_name : str , task_id : str
768788 ):
769- run_id_key , run_id_value = translate_run_key (run_id )
770- task_id_key , task_id_value = translate_task_key (task_id )
771- filter_dict = {
772- "flow_id" : flow_id ,
773- run_id_key : run_id_value ,
774- "step_name" : step_name ,
775- task_id_key : task_id_value ,
776- }
789+ filter_dict = self .get_filter_dict (flow_id , run_id , step_name , task_id )
777790 return await self .get_records (filter_dict = filter_dict )
778791
779792
@@ -856,7 +869,20 @@ async def add_artifact(
856869 }
857870 return await self .create_record (dict )
858871
859- async def get_artifacts_in_runs (self , flow_id : str , run_id : int ):
872+ @staticmethod
873+ def get_filter_dict (
874+ flow_id : str , run_id : str , step_name : str , task_id : str , name : str ):
875+ run_id_key , run_id_value = translate_run_key (run_id )
876+ task_id_key , task_id_value = translate_task_key (task_id )
877+ return {
878+ "flow_id" : flow_id ,
879+ run_id_key : run_id_value ,
880+ "step_name" : step_name ,
881+ task_id_key : task_id_value ,
882+ '"name"' : name ,
883+ }
884+
885+ async def get_artifacts_in_runs (self , flow_id : str , run_id : str ):
860886 run_id_key , run_id_value = translate_run_key (run_id )
861887 filter_dict = {
862888 "flow_id" : flow_id ,
@@ -865,7 +891,7 @@ async def get_artifacts_in_runs(self, flow_id: str, run_id: int):
865891 return await self .get_records (filter_dict = filter_dict ,
866892 ordering = self .ordering )
867893
868- async def get_artifact_in_steps (self , flow_id : str , run_id : int , step_name : str ):
894+ async def get_artifact_in_steps (self , flow_id : str , run_id : str , step_name : str ):
869895 run_id_key , run_id_value = translate_run_key (run_id )
870896 filter_dict = {
871897 "flow_id" : flow_id ,
@@ -876,7 +902,7 @@ async def get_artifact_in_steps(self, flow_id: str, run_id: int, step_name: str)
876902 ordering = self .ordering )
877903
878904 async def get_artifact_in_task (
879- self , flow_id : str , run_id : int , step_name : str , task_id : int
905+ self , flow_id : str , run_id : str , step_name : str , task_id : str
880906 ):
881907 run_id_key , run_id_value = translate_run_key (run_id )
882908 task_id_key , task_id_value = translate_task_key (task_id )
@@ -890,16 +916,8 @@ async def get_artifact_in_task(
890916 ordering = self .ordering )
891917
892918 async def get_artifact (
893- self , flow_id : str , run_id : int , step_name : str , task_id : int , name : str
919+ self , flow_id : str , run_id : str , step_name : str , task_id : str , name : str
894920 ):
895- run_id_key , run_id_value = translate_run_key (run_id )
896- task_id_key , task_id_value = translate_task_key (task_id )
897- filter_dict = {
898- "flow_id" : flow_id ,
899- run_id_key : run_id_value ,
900- "step_name" : step_name ,
901- task_id_key : task_id_value ,
902- '"name"' : name ,
903- }
921+ filter_dict = self .get_filter_dict (flow_id , run_id , step_name , task_id , name )
904922 return await self .get_records (filter_dict = filter_dict ,
905923 fetch_single = True , ordering = self .ordering )
0 commit comments