From 3248197d0fb5caf165136a3a41482579ab87bbe1 Mon Sep 17 00:00:00 2001 From: David Sutherland Date: Fri, 22 Sep 2023 12:31:21 +1200 Subject: [PATCH] add sequential arg option and to wall_clock as True --- cylc/flow/cfgspec/workflow.py | 4 ++-- cylc/flow/xtrigger_mgr.py | 30 +++++++++++++++++++++--------- cylc/flow/xtriggers/wall_clock.py | 4 +++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cylc/flow/cfgspec/workflow.py b/cylc/flow/cfgspec/workflow.py index 1974b320760..db8f6534453 100644 --- a/cylc/flow/cfgspec/workflow.py +++ b/cylc/flow/cfgspec/workflow.py @@ -791,8 +791,8 @@ def get_script_common_text(this: str, example: Optional[str] = None): Instead of out to the runahead limit (default: ``False``). This workflow wide default can be overridden by a reserved - keyword argument in the xtrigger function declaration - (``sequential=True/False``). + keyword argument in the xtrigger function declaration and/or + function (``sequential=True/False``). The presence of one sequential xtrigger on a parentless task with multiple xtriggers will cause sequential behavior. diff --git a/cylc/flow/xtrigger_mgr.py b/cylc/flow/xtrigger_mgr.py index a731fb3fe5f..a76133a00c6 100644 --- a/cylc/flow/xtrigger_mgr.py +++ b/cylc/flow/xtrigger_mgr.py @@ -311,15 +311,27 @@ def validate_xtrigger(label: str, fctx: SubFuncContext, fdir: str) -> None: fname, f"'{fname}' not callable in xtrigger module '{fname}'", ) - if 'sequential' in getfullargspec(func).args: - raise XtriggerConfigError( - label, - fname, - ( - f"xtrigger module '{fname}' contains reserved" - " argument name 'sequential'" - ), - ) + x_argspec = getfullargspec(func) + if 'sequential' in x_argspec.args: + if ( + x_argspec.defaults is None + or not isinstance( + x_argspec.defaults[x_argspec.args.index('sequential')], + bool + ) + ): + raise XtriggerConfigError( + label, + fname, + ( + f"xtrigger module '{fname}' contains reserved argument" + " name 'sequential' that has no boolean default" + ), + ) + elif 'sequential' not in fctx.func_kwargs: + fctx.func_kwargs['sequential'] = x_argspec.defaults[ + x_argspec.args.index('sequential') + ] # Check any string templates in the function arg values (note this # won't catch bad task-specific values - which are added dynamically). diff --git a/cylc/flow/xtriggers/wall_clock.py b/cylc/flow/xtriggers/wall_clock.py index 3c50d956f0a..b849e271fc5 100644 --- a/cylc/flow/xtriggers/wall_clock.py +++ b/cylc/flow/xtriggers/wall_clock.py @@ -19,11 +19,13 @@ from time import time -def wall_clock(trigger_time=None): +def wall_clock(trigger_time=None, sequential=True): """Return True after the desired wall clock time, False. Args: trigger_time (int): Trigger time as seconds since Unix epoch. + sequential (bool): + Used by the workflow to flag corresponding xtriggers as sequential. """ return time() > trigger_time