@@ -55,6 +55,7 @@ def create_status_table(self, jobs_info: dict[str, dict]) -> Table:
5555 table .add_column ("Status" )
5656 table .add_column ("Runtime" , justify = "right" , style = "magenta" )
5757 table .add_column ("Job ID" , style = "yellow" )
58+ table .add_column ("Job Name" , style = "blue" )
5859 table .add_column ("Config" , style = "green" )
5960
6061 for job_id , info in jobs_info .items ():
@@ -65,43 +66,61 @@ def create_status_table(self, jobs_info: dict[str, dict]) -> Table:
6566 table .add_row (
6667 status_colored ,
6768 info ["runtime" ],
68- job_id ,
69+ job_id [:13 ] + "..." ,
70+ info ["job_name" ],
6971 info ["config" ],
7072 )
7173
7274 return table
7375
74- def monitor (self , job_id_to_config : dict [str , str ]) -> None :
75- """Monitor submitted jobs and display status in real-time"""
76+ def monitor (self , job_info_dict : dict [str , dict [str , str ]]) -> None :
77+ """Monitor submitted jobs and display status in real-time.
78+
79+ Args:
80+ job_info_dict: Dict mapping job_id -> {job_name, config}
81+ """
7682 jobs_info : dict [str , dict ] = {}
77- start_times : dict [str , float ] = {job_id : time .time () for job_id in job_id_to_config }
83+ start_times : dict [str , float ] = {job_id : time .time () for job_id in job_info_dict }
84+ completion_times : dict [str , float ] = {}
7885
7986 self .console .print ("\n [bold green]Note:[/] You can ^C this script without your jobs dying\n " )
8087
8188 try :
8289 with Live (self .create_status_table ({}), refresh_per_second = 1 , console = self .console ) as live :
8390 while True :
8491 all_done = True
85- for job_id , config in job_id_to_config .items ():
92+ for job_id , info in job_info_dict .items ():
8693 try :
8794 job_status = self .get_job_status (job_id )
8895 status = job_status ["status" ]
89- elapsed = time .time () - start_times [job_id ]
96+
97+ # Freeze runtime when job reaches terminal state
98+ if status in ["SUCCEEDED" , "FAILED" ] and job_id not in completion_times :
99+ completion_times [job_id ] = time .time ()
100+
101+ if job_id in completion_times :
102+ elapsed = completion_times [job_id ] - start_times [job_id ]
103+ else :
104+ elapsed = time .time () - start_times [job_id ]
90105
91106 jobs_info [job_id ] = {
92107 "status" : status ,
93108 "runtime" : self .format_duration (elapsed ),
94- "config" : config ,
109+ "job_name" : info ["job_name" ],
110+ "config" : info ["config" ],
95111 }
96112
97113 if status not in ["SUCCEEDED" , "FAILED" ]:
98114 all_done = False
99115 except Exception as e :
100116 logger .error (f"Error getting status for { job_id } : { e } " , exc_info = True )
117+ if job_id not in completion_times :
118+ completion_times [job_id ] = time .time ()
101119 jobs_info [job_id ] = {
102120 "status" : "ERROR" ,
103- "runtime" : self .format_duration (time .time () - start_times [job_id ]),
104- "config" : config ,
121+ "runtime" : self .format_duration (completion_times [job_id ] - start_times [job_id ]),
122+ "job_name" : info ["job_name" ],
123+ "config" : info ["config" ],
105124 }
106125
107126 live .update (self .create_status_table (jobs_info ))
0 commit comments