#!jinja2
[cylc]
    UTC mode=True
    cycle point format = %Y
    [[events]]
        abort on stalled = True
        abort on inactivity = True
        inactivity = P1M
        startup handler = cylc release '%(suite)s'
[scheduling]
    initial cycle point = 2016
    final cycle point = 2020
    [[dependencies]]
        [[[P1Y]]]
            graph=t1[-P1Y] => t1
[runtime]
    [[t1]]
        script = """
wait "${CYLC_TASK_MESSAGE_STARTED_PID}" 2>/dev/null || true
if [[ "${CYLC_TASK_CYCLE_POINT}" == '2017' ]]; then
    LOG="${CYLC_SUITE_LOG_DIR}/log"
    while ! grep -qF '[t1.2017] -(current:submitted)> started' "${LOG}"; do
        sleep 1  # make sure started message is recorded in suite
    done
    sleep 2
    cylc broadcast "${CYLC_SUITE_NAME}" -p '2017' -n 't1' --set='script=true'
    cylc hold "${CYLC_SUITE_NAME}"
    while ! grep -qF 'INFO - Command succeeded: hold_suite()' "${LOG}"; do
        sleep 1  # make sure hold completes
    done
    sleep 2
    (cd "${CYLC_SUITE_DEF_PATH}"; cp -p 'suite2.rc' 'suite.rc')
    cylc reload "${CYLC_SUITE_NAME}"
    while ! grep -q 'Reload completed' "${LOG}"; do
        sleep 1  # make sure reload completes
    done
    cylc insert "${CYLC_SUITE_NAME}" 't2.2017'
    while ! cylc show "${CYLC_SUITE_NAME}" 't2.2017' 1>'/dev/null' 2>&1; do
        sleep 1  # make sure insert completes
    done
    sleep 2
    cylc release "${CYLC_SUITE_NAME}"
fi
"""
        [[[job]]]
            execution time limit = PT50S
        [[[events]]]
            failed handler = cylc release '%(suite)s'
