Skip to content

Commit 8c9cea5

Browse files
committed
Adding kill switch trigger. If a job's processStatus != "success" and runtimeContext.on_error = "kill", then the switch is activated. WorkflowKillSwitch is raised so it can be handled at the workflow and executor levels
1 parent d9c6dda commit 8c9cea5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

cwltool/errors.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ class ArgumentException(Exception):
1212

1313
class GraphTargetMissingException(WorkflowException):
1414
"""When a ``$graph`` is encountered and there is no target and no ``main``/``#main``."""
15+
16+
17+
class WorkflowKillSwitch(Exception):
18+
"""When processStatus != "success" and on-error=kill, raise this exception."""
19+
20+
def __init__(self, job_id, rcode):
21+
self.job_id = job_id
22+
self.rcode = rcode
23+
24+
def __str__(self):
25+
return f'[job {self.job_id}] activated kill switch with return code {self.rcode}'

cwltool/job.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from .builder import Builder
4545
from .context import RuntimeContext
4646
from .cuda import cuda_check
47-
from .errors import UnsupportedRequirement, WorkflowException
47+
from .errors import UnsupportedRequirement, WorkflowException, WorkflowKillSwitch
4848
from .loghandler import _logger
4949
from .pathmapper import MapperEnt, PathMapper
5050
from .process import stage_files
@@ -362,14 +362,19 @@ def stderr_stdout_log_path(
362362
processStatus = "permanentFail"
363363

364364
if processStatus != "success":
365-
if rcode < 0:
365+
if runtimeContext.kill_switch.is_set():
366+
return
367+
elif rcode < 0:
366368
_logger.warning(
367369
"[job %s] was terminated by signal: %s",
368370
self.name,
369371
signal.Signals(-rcode).name,
370372
)
371373
else:
372374
_logger.warning("[job %s] exited with status: %d", self.name, rcode)
375+
if runtimeContext.on_error == "kill":
376+
runtimeContext.kill_switch.set()
377+
raise WorkflowKillSwitch(self.name, rcode)
373378

374379
if "listing" in self.generatefiles:
375380
if self.generatemapper:
@@ -400,6 +405,8 @@ def stderr_stdout_log_path(
400405
except WorkflowException as err:
401406
_logger.error("[job %s] Job error:\n%s", self.name, str(err))
402407
processStatus = "permanentFail"
408+
except WorkflowKillSwitch:
409+
raise
403410
except Exception:
404411
_logger.exception("Exception while running job")
405412
processStatus = "permanentFail"

0 commit comments

Comments
 (0)