#!jinja2

title = "test all event hooks"

# simple generic handler in the suite bin dir:
{% set HANDLER = "handler.sh" %}
{% set EVNTLOG = "$CYLC_SUITE_LOG_DIR/events.log" %}

[cylc]
    [[environment]]
        EVNTLOG = {{ EVNTLOG }}
    [[reference test]]
        live mode suite timeout = PT1M
        suite shutdown event handler = log-check.sh
        expected task failures = bar.1, baz.1
 
[scheduling]
    [[dependencies]]
        graph = """
          prep => foo & bar & baz
      bar:submit-fail & baz:fail & foo => done
           done => !bar & !baz
                """
[runtime]
    [[root]]
        # make the event handler log available to gcylc:
        extra log files = {{ EVNTLOG }}
        script = "true" # fast

    [[prep]]
        script = """
printf "%-20s %-8s %s\n" EVENT TASK MESSAGE > {{ EVNTLOG }}
                            """
    [[foo]]
        # timeout, retry, warning, succeeded 
        script = """
if [[ $CYLC_TASK_TRY_NUMBER == 1 ]]; then
    false
else
    sleep 10; cylc task message -p WARNING 'this is a user-defined warning message'
fi"""
        [[[job]]]
            execution retry delays = PT3S
        [[[events]]]
            succeeded handler = {{ HANDLER }}
            warning handler = {{ HANDLER }}
            retry handler = {{ HANDLER }}
            execution timeout = PT3S
            execution timeout handler = {{ HANDLER }}

    [[bar]]
        # submission retry and submission failed
        [[[events]]]
            submission failed handler = {{ HANDLER }}
            submission retry handler = {{ HANDLER }}
        [[[job]]]
            submission retry delays = PT3S
        [[[remote]]]
            host = NOHOST

     [[baz]]
        # submitted, submission timeout, started, failed
        init-script = sleep 15
        script = false
        [[[events]]]
            submitted handler = {{ HANDLER }}
            started handler = {{ HANDLER }}
            failed handler = {{ HANDLER }}
            submission timeout = PT3S
            submission timeout handler = {{ HANDLER }}
