#!Jinja2

{% set NSLEEP = NSLEEP | default(1) %}
{% set EXIT = EXIT | default("false") %}

[cylc]
    [[events]]
        abort on stalled = True
[scheduling]
    [[dependencies]]
        graph = foo
[runtime]
    [[foo]]
        exit-script = echo "Cheesy peas!"
        err-script = echo "$1 Oops!"
        script = """
echo "HELLO"
if {{EXIT}}; then
    exit 0
fi
# This must not be a single monolothic sleep. If a command is running when
# bash receives a signal that a trap is set for, it waits for the command to
# complete before executing the trap. We want a quick exit, to make it
# obvious that the TERM signal had the intended effect.
for I in $(seq 1 {{NSLEEP}}); do
    echo $I
    sleep 1
done
echo "BYE"
        """
