@@ -65,11 +65,13 @@ def get_disk_info(metadata):
6565 return float (0 ), float (0 )
6666
6767
68- def was_preemptible_vm (metadata ):
68+ def was_preemptible_vm (metadata , was_cached ):
6969 """
70- Source : https://github.com/broadinstitute/dsde-pipelines/blob/develop/scripts/calculate_cost.py
70+ Modified from : https://github.com/broadinstitute/dsde-pipelines/blob/develop/scripts/calculate_cost.py
7171 """
72- if "runtimeAttributes" in metadata and "preemptible" in metadata ['runtimeAttributes' ]:
72+ if was_cached :
73+ return True # if call cached, not any type of VM, but don't inflate nonpreemptible count
74+ elif "runtimeAttributes" in metadata and "preemptible" in metadata ['runtimeAttributes' ]:
7375 pe_count = int (metadata ['runtimeAttributes' ]["preemptible" ])
7476 attempt = int (metadata ['attempt' ])
7577
@@ -90,11 +92,14 @@ def calculate_start_end(call_info, override_warning=False, alias=None):
9092 """
9193 Modified from: https://github.com/broadinstitute/dsde-pipelines/blob/develop/scripts/calculate_cost.py
9294 """
93- job_id = call_info ['jobId' ].split ('/' )[- 1 ]
94- if alias is None or alias == "" :
95- alias = job_id
96- else :
97- alias += "." + job_id
95+ if 'jobId' in call_info :
96+ job_id = call_info ['jobId' ].split ('/' )[- 1 ]
97+ if alias is None or alias == "" :
98+ alias = job_id
99+ else :
100+ alias += "." + job_id
101+ elif alias is None or alias == "" :
102+ alias = "NA"
98103
99104 # get start (start time of VM start) & end time (end time of 'ok') according to metadata
100105 start = None
@@ -131,10 +136,11 @@ def calculate_start_end(call_info, override_warning=False, alias=None):
131136 if 'end' in call_info :
132137 end = dateutil .parser .parse (call_info ['end' ])
133138 elif override_warning :
134- logging .warning ("End time not found, omitting job {}" .format (call_info [ 'jobId' ] ))
139+ logging .warning ("End time not found, omitting job {}" .format (alias ))
135140 end = start
136141 else :
137- raise RuntimeError (("End time not found for job {} (may be running or have been aborted). Run again with --override-warning to continue anyway and omit the job." .format (alias )))
142+ raise RuntimeError ((f"End time not found for job { alias } (may be running or have been aborted)."
143+ " Run again with --override-warning to continue anyway and omit the job." ))
138144
139145 return start , end
140146
@@ -242,7 +248,7 @@ def get_calls(m, override_warning=False, alias=None):
242248
243249 cached = used_cached_results (m )
244250
245- preemptible = was_preemptible_vm (m )
251+ preemptible = was_preemptible_vm (m , cached )
246252 preemptible_cpu = 0
247253 nonpreemptible_cpu = 0
248254 if preemptible :
@@ -407,7 +413,7 @@ def write_cached_warning(cached_file):
407413 global CACHED
408414 global NUM_CACHED
409415 if NUM_CACHED > 0 :
410- logging .info ("%d cached task(s) found, writing tasks to %s." % (NUM_CACHED , cached_file ))
416+ logging .info ("%d cached task(s) found, writing task(s) to %s." % (NUM_CACHED , cached_file ))
411417 with open (cached_file , 'w' ) as cached_out :
412418 cached_out .write ("#task_name\t num_cached\n " )
413419 cached_out .write ("all_tasks\t %d\n " % NUM_CACHED )
@@ -420,7 +426,7 @@ def write_nonpreemptible_vms(vms_file):
420426 global NUM_NONPREEMPTIBLE
421427 global NONPREEMPTIBLE_TASKS
422428 if NUM_NONPREEMPTIBLE > 0 :
423- logging .info ("%d non-preemptible VM(s) found, writing tasks to %s." % (NUM_NONPREEMPTIBLE , vms_file ))
429+ logging .info ("%d non-preemptible VM(s) found, writing task(s) to %s." % (NUM_NONPREEMPTIBLE , vms_file ))
424430 with open (vms_file , 'w' ) as vms_out :
425431 vms_out .write ("#task_name\t num_nonpreemptible\n " )
426432 vms_out .write ("all_tasks\t %d\n " % NUM_NONPREEMPTIBLE )
0 commit comments