@@ -298,6 +298,7 @@ def _execute(
298
298
"{}" .format (runtimeContext )
299
299
)
300
300
outputs : CWLObjectType = {}
301
+ processStatus = "indeterminate"
301
302
try :
302
303
stdin_path = None
303
304
if self .stdin is not None :
@@ -369,6 +370,7 @@ def stderr_stdout_log_path(
369
370
370
371
if processStatus != "success" :
371
372
if runtimeContext .kill_switch .is_set ():
373
+ processStatus = "killed"
372
374
return
373
375
elif rcode < 0 :
374
376
_logger .warning (
@@ -412,62 +414,64 @@ def stderr_stdout_log_path(
412
414
_logger .error ("[job %s] Job error:\n %s" , self .name , str (err ))
413
415
processStatus = "permanentFail"
414
416
except WorkflowKillSwitch :
417
+ processStatus = "permanentFail"
415
418
raise
416
419
except Exception :
417
420
_logger .exception ("Exception while running job" )
418
421
processStatus = "permanentFail"
419
- if (
420
- runtimeContext .research_obj is not None
421
- and self .prov_obj is not None
422
- and runtimeContext .process_run_id is not None
423
- ):
424
- # creating entities for the outputs produced by each step (in the provenance document)
425
- self .prov_obj .record_process_end (
426
- str (self .name ),
427
- runtimeContext .process_run_id ,
428
- outputs ,
429
- datetime .datetime .now (),
430
- )
431
- if processStatus != "success" :
432
- _logger .warning ("[job %s] completed %s" , self .name , processStatus )
433
- else :
434
- _logger .info ("[job %s] completed %s" , self .name , processStatus )
435
-
436
- if _logger .isEnabledFor (logging .DEBUG ):
437
- _logger .debug ("[job %s] outputs %s" , self .name , json_dumps (outputs , indent = 4 ))
438
-
439
- if self .generatemapper is not None and runtimeContext .secret_store is not None :
440
- # Delete any runtime-generated files containing secrets.
441
- for _ , p in self .generatemapper .items ():
442
- if p .type == "CreateFile" :
443
- if runtimeContext .secret_store .has_secret (p .resolved ):
444
- host_outdir = self .outdir
445
- container_outdir = self .builder .outdir
446
- host_outdir_tgt = p .target
447
- if p .target .startswith (container_outdir + "/" ):
448
- host_outdir_tgt = os .path .join (
449
- host_outdir , p .target [len (container_outdir ) + 1 :]
450
- )
451
- os .remove (host_outdir_tgt )
452
-
453
- if runtimeContext .workflow_eval_lock is None :
454
- raise WorkflowException ("runtimeContext.workflow_eval_lock must not be None" )
455
-
456
- if self .output_callback :
457
- with runtimeContext .workflow_eval_lock :
458
- self .output_callback (outputs , processStatus )
459
-
460
- if runtimeContext .rm_tmpdir and self .stagedir is not None and os .path .exists (self .stagedir ):
461
- _logger .debug (
462
- "[job %s] Removing input staging directory %s" ,
463
- self .name ,
464
- self .stagedir ,
465
- )
466
- shutil .rmtree (self .stagedir , True )
422
+ finally :
423
+ if (
424
+ runtimeContext .research_obj is not None
425
+ and self .prov_obj is not None
426
+ and runtimeContext .process_run_id is not None
427
+ ):
428
+ # creating entities for the outputs produced by each step (in the provenance document)
429
+ self .prov_obj .record_process_end (
430
+ str (self .name ),
431
+ runtimeContext .process_run_id ,
432
+ outputs ,
433
+ datetime .datetime .now (),
434
+ )
435
+ if processStatus != "success" :
436
+ _logger .warning ("[job %s] completed %s" , self .name , processStatus )
437
+ else :
438
+ _logger .info ("[job %s] completed %s" , self .name , processStatus )
439
+
440
+ if _logger .isEnabledFor (logging .DEBUG ):
441
+ _logger .debug ("[job %s] outputs %s" , self .name , json_dumps (outputs , indent = 4 ))
442
+
443
+ if self .generatemapper is not None and runtimeContext .secret_store is not None :
444
+ # Delete any runtime-generated files containing secrets.
445
+ for _ , p in self .generatemapper .items ():
446
+ if p .type == "CreateFile" :
447
+ if runtimeContext .secret_store .has_secret (p .resolved ):
448
+ host_outdir = self .outdir
449
+ container_outdir = self .builder .outdir
450
+ host_outdir_tgt = p .target
451
+ if p .target .startswith (container_outdir + "/" ):
452
+ host_outdir_tgt = os .path .join (
453
+ host_outdir , p .target [len (container_outdir ) + 1 :]
454
+ )
455
+ os .remove (host_outdir_tgt )
456
+
457
+ if runtimeContext .workflow_eval_lock is None :
458
+ raise WorkflowException ("runtimeContext.workflow_eval_lock must not be None" )
459
+
460
+ if self .output_callback :
461
+ with runtimeContext .workflow_eval_lock :
462
+ self .output_callback (outputs , processStatus )
463
+
464
+ if runtimeContext .rm_tmpdir and self .stagedir is not None and os .path .exists (self .stagedir ):
465
+ _logger .debug (
466
+ "[job %s] Removing input staging directory %s" ,
467
+ self .name ,
468
+ self .stagedir ,
469
+ )
470
+ shutil .rmtree (self .stagedir , True )
467
471
468
- if runtimeContext .rm_tmpdir :
469
- _logger .debug ("[job %s] Removing temporary directory %s" , self .name , self .tmpdir )
470
- shutil .rmtree (self .tmpdir , True )
472
+ if runtimeContext .rm_tmpdir :
473
+ _logger .debug ("[job %s] Removing temporary directory %s" , self .name , self .tmpdir )
474
+ shutil .rmtree (self .tmpdir , True )
471
475
472
476
@abstractmethod
473
477
def _required_env (self ) -> Dict [str , str ]:
0 commit comments