Skip to content

Commit

Permalink
Merge pull request #9 from oliver-sanders/xtrigger-stuff
Browse files Browse the repository at this point in the history
xtiggers: flesh out validation
  • Loading branch information
wxtim authored Apr 25, 2024
2 parents f445bbf + 85e0ec1 commit 33a6bd0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/plugins/xtriggers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ These xtriggers can be registered in the package's ``setup.cfg`` or

It is recommended to implement only one xtrigger per module. This allows
you to write a ``validate`` function for each xtrigger - see
:py:mod:`cylc.flow.xtriggers.xrandom` for an example.
:ref:`user-guide.xtrigger-validation-functions`.

36 changes: 24 additions & 12 deletions src/user-guide/writing-workflows/external-triggers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,9 @@ properties:
passed to the function as such
- If a trigger function depends on files or directories (for example)
that might not exist when the function is first called, just return
unsatisfied until everything required does exist.
- The module containing the xtrigger function may also contain a ``validate``
function taking a single argument, which is a dictionary of all the arguments
passed to the xtrigger function in ``flow.cylc``. It should raise an
exception if validation fails. See
:py:mod:`cylc.flow.xtriggers.xrandom`
for an example of a validate function.
- The arguments you call the xtrigger function with are automatically
validated against the function signature, so you don't necessarily need
to check for the presence of arguments or their types in the validate
function. However, you may want to check that the values are of the correct
type or within a certain range.
- The module can also provide a ``validate`` function for checking configured
arguments / keyword arguments, see
:ref:`user-guide.xtrigger-validation-functions` for details.

.. note::

Expand Down Expand Up @@ -348,6 +339,26 @@ The :term:`scheduler` manages trigger functions as follows:
the workflow log in debug mode (stdout is needed to communicate return values
from the sub-process in which the function executes)


.. _user-guide.xtrigger-validation-functions:

Xtrigger Validation Functions
-----------------------------

The arguments you call the xtrigger function with are automatically validated
against the function signature, however, you might wish to add extra validation
logic to your custom xtrigger, e.g. to check argument types or values.

If a function named ``validate`` is present alongside the xtrigger in its
module, it will be automatically called with a dictionary of all the arguments
passed to the xtrigger function in the workflow config. It should raise a
:py:obj:`cylc.flow.exceptions.WorkflowConfigError` exception if an error is
detected.

The :py:mod:`cylc.flow.xtriggers.xrandom` xtrigger module contains an example
of an xtrigger validation function.


.. _Built-in Toy Xtriggers:

Toy Examples
Expand Down Expand Up @@ -391,6 +402,7 @@ time (useful for testing the effect of a long-running trigger function
success. The function signature is:

.. automodule:: cylc.flow.xtriggers.xrandom
:members: xrandom

The ``percent`` argument sets the odds of success in any given call;
``secs`` is the number of seconds to sleep before returning; and the
Expand Down

0 comments on commit 33a6bd0

Please sign in to comment.