Skip to content

Commit d7b7712

Browse files
AlexTatemr-c
authored andcommitted
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 572e865 commit d7b7712

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
@@ -18,3 +18,14 @@ class UnsupportedRequirement(WorkflowException):
1818

1919
class ArgumentException(Exception):
2020
"""Mismatched command line arguments provided."""
21+
22+
23+
class WorkflowKillSwitch(Exception):
24+
"""When processStatus != "success" and on-error=kill, raise this exception."""
25+
26+
def __init__(self, job_id, rcode):
27+
self.job_id = job_id
28+
self.rcode = rcode
29+
30+
def __str__(self):
31+
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
@@ -30,7 +30,7 @@
3030
from .builder import Builder
3131
from .context import RuntimeContext
3232
from .cuda import cuda_check
33-
from .errors import UnsupportedRequirement, WorkflowException
33+
from .errors import UnsupportedRequirement, WorkflowException, WorkflowKillSwitch
3434
from .loghandler import _logger
3535
from .pathmapper import MapperEnt, PathMapper
3636
from .process import stage_files
@@ -348,14 +348,19 @@ def stderr_stdout_log_path(
348348
processStatus = "permanentFail"
349349

350350
if processStatus != "success":
351-
if rcode < 0:
351+
if runtimeContext.kill_switch.is_set():
352+
return
353+
elif rcode < 0:
352354
_logger.warning(
353355
"[job %s] was terminated by signal: %s",
354356
self.name,
355357
signal.Signals(-rcode).name,
356358
)
357359
else:
358360
_logger.warning("[job %s] exited with status: %d", self.name, rcode)
361+
if runtimeContext.on_error == "kill":
362+
runtimeContext.kill_switch.set()
363+
raise WorkflowKillSwitch(self.name, rcode)
359364

360365
if "listing" in self.generatefiles:
361366
if self.generatemapper:
@@ -386,6 +391,8 @@ def stderr_stdout_log_path(
386391
except WorkflowException as err:
387392
_logger.error("[job %s] Job error:\n%s", self.name, str(err))
388393
processStatus = "permanentFail"
394+
except WorkflowKillSwitch:
395+
raise
389396
except Exception:
390397
_logger.exception("Exception while running job")
391398
processStatus = "permanentFail"

0 commit comments

Comments
 (0)