@@ -284,6 +284,7 @@ def _execute(
284
284
"{}" .format (runtimeContext )
285
285
)
286
286
outputs : CWLObjectType = {}
287
+ processStatus = "indeterminate"
287
288
try :
288
289
stdin_path = None
289
290
if self .stdin is not None :
@@ -355,6 +356,7 @@ def stderr_stdout_log_path(
355
356
356
357
if processStatus != "success" :
357
358
if runtimeContext .kill_switch .is_set ():
359
+ processStatus = "killed"
358
360
return
359
361
elif rcode < 0 :
360
362
_logger .warning (
@@ -398,62 +400,64 @@ def stderr_stdout_log_path(
398
400
_logger .error ("[job %s] Job error:\n %s" , self .name , str (err ))
399
401
processStatus = "permanentFail"
400
402
except WorkflowKillSwitch :
403
+ processStatus = "permanentFail"
401
404
raise
402
405
except Exception :
403
406
_logger .exception ("Exception while running job" )
404
407
processStatus = "permanentFail"
405
- if (
406
- runtimeContext .research_obj is not None
407
- and self .prov_obj is not None
408
- and runtimeContext .process_run_id is not None
409
- ):
410
- # creating entities for the outputs produced by each step (in the provenance document)
411
- self .prov_obj .record_process_end (
412
- str (self .name ),
413
- runtimeContext .process_run_id ,
414
- outputs ,
415
- datetime .datetime .now (),
416
- )
417
- if processStatus != "success" :
418
- _logger .warning ("[job %s] completed %s" , self .name , processStatus )
419
- else :
420
- _logger .info ("[job %s] completed %s" , self .name , processStatus )
421
-
422
- if _logger .isEnabledFor (logging .DEBUG ):
423
- _logger .debug ("[job %s] outputs %s" , self .name , json_dumps (outputs , indent = 4 ))
424
-
425
- if self .generatemapper is not None and runtimeContext .secret_store is not None :
426
- # Delete any runtime-generated files containing secrets.
427
- for _ , p in self .generatemapper .items ():
428
- if p .type == "CreateFile" :
429
- if runtimeContext .secret_store .has_secret (p .resolved ):
430
- host_outdir = self .outdir
431
- container_outdir = self .builder .outdir
432
- host_outdir_tgt = p .target
433
- if p .target .startswith (container_outdir + "/" ):
434
- host_outdir_tgt = os .path .join (
435
- host_outdir , p .target [len (container_outdir ) + 1 :]
436
- )
437
- os .remove (host_outdir_tgt )
438
-
439
- if runtimeContext .workflow_eval_lock is None :
440
- raise WorkflowException ("runtimeContext.workflow_eval_lock must not be None" )
441
-
442
- if self .output_callback :
443
- with runtimeContext .workflow_eval_lock :
444
- self .output_callback (outputs , processStatus )
445
-
446
- if runtimeContext .rm_tmpdir and self .stagedir is not None and os .path .exists (self .stagedir ):
447
- _logger .debug (
448
- "[job %s] Removing input staging directory %s" ,
449
- self .name ,
450
- self .stagedir ,
451
- )
452
- shutil .rmtree (self .stagedir , True )
408
+ finally :
409
+ if (
410
+ runtimeContext .research_obj is not None
411
+ and self .prov_obj is not None
412
+ and runtimeContext .process_run_id is not None
413
+ ):
414
+ # creating entities for the outputs produced by each step (in the provenance document)
415
+ self .prov_obj .record_process_end (
416
+ str (self .name ),
417
+ runtimeContext .process_run_id ,
418
+ outputs ,
419
+ datetime .datetime .now (),
420
+ )
421
+ if processStatus != "success" :
422
+ _logger .warning ("[job %s] completed %s" , self .name , processStatus )
423
+ else :
424
+ _logger .info ("[job %s] completed %s" , self .name , processStatus )
425
+
426
+ if _logger .isEnabledFor (logging .DEBUG ):
427
+ _logger .debug ("[job %s] outputs %s" , self .name , json_dumps (outputs , indent = 4 ))
428
+
429
+ if self .generatemapper is not None and runtimeContext .secret_store is not None :
430
+ # Delete any runtime-generated files containing secrets.
431
+ for _ , p in self .generatemapper .items ():
432
+ if p .type == "CreateFile" :
433
+ if runtimeContext .secret_store .has_secret (p .resolved ):
434
+ host_outdir = self .outdir
435
+ container_outdir = self .builder .outdir
436
+ host_outdir_tgt = p .target
437
+ if p .target .startswith (container_outdir + "/" ):
438
+ host_outdir_tgt = os .path .join (
439
+ host_outdir , p .target [len (container_outdir ) + 1 :]
440
+ )
441
+ os .remove (host_outdir_tgt )
442
+
443
+ if runtimeContext .workflow_eval_lock is None :
444
+ raise WorkflowException ("runtimeContext.workflow_eval_lock must not be None" )
445
+
446
+ if self .output_callback :
447
+ with runtimeContext .workflow_eval_lock :
448
+ self .output_callback (outputs , processStatus )
449
+
450
+ if runtimeContext .rm_tmpdir and self .stagedir is not None and os .path .exists (self .stagedir ):
451
+ _logger .debug (
452
+ "[job %s] Removing input staging directory %s" ,
453
+ self .name ,
454
+ self .stagedir ,
455
+ )
456
+ shutil .rmtree (self .stagedir , True )
453
457
454
- if runtimeContext .rm_tmpdir :
455
- _logger .debug ("[job %s] Removing temporary directory %s" , self .name , self .tmpdir )
456
- shutil .rmtree (self .tmpdir , True )
458
+ if runtimeContext .rm_tmpdir :
459
+ _logger .debug ("[job %s] Removing temporary directory %s" , self .name , self .tmpdir )
460
+ shutil .rmtree (self .tmpdir , True )
457
461
458
462
@abstractmethod
459
463
def _required_env (self ) -> dict [str , str ]:
0 commit comments