[meta]
    title = "Capture baz prereqs and outputs after various state changes."
[cylc]
    [[events]]
        timeout = PT1M
        abort on timeout = True
    [[parameters]]
        m = succeeded, expired, failed, submit-failed, waiting
        x = 1..4
    [[parameter templates]]
        m = %(m)s
[scheduling]
    [[dependencies]]
        graph = """FOO:succeed-any & BAR:finish-all => baz & baz2
                     baz => <m=succeeded>
                       <m-1> => <m>
                         <m=waiting> => trigger"""
[runtime]
    [[FOO, BAR]]
    [[RESET]]
        pre-script = """
            if [[ "${CYLC_TASK_NAME}" == "waiting" ]]; then
                # Remove upstream outputs so it's clear that prereqs get unset.
                cylc remove ${CYLC_SUITE_NAME} FOO
                cylc remove ${CYLC_SUITE_NAME} BAR
                sleep 5
            fi
            NEW_STATE=${CYLC_TASK_NAME}
            CUR_STATE=$(cylc dump --tasks ${CYLC_SUITE_NAME} \
                | grep 'baz, 1' | awk '{print $3}' | sed -e 's/,//')
            if [[ "${NEW_STATE}" != "${CUR_STATE}" ]]; then
                cylc reset --state=${NEW_STATE} ${CYLC_SUITE_NAME} baz.1
            fi
            sleep 5"""
    [[SHOW]]
        post-script = """
            sleep 5
            OUT=${CYLC_SUITE_SHARE_DIR}/${CYLC_TASK_NAME}.out
            cylc show ${CYLC_SUITE_NAME} baz.1 > ${OUT}"""
    [[foo<x>]]
        inherit = FOO
        script = false
    [[foo<x=4>]]
        script = true
    [[bar<x>]]
        inherit = BAR
        script = false
    [[bar<x=4>]]
        inherit = BAR, SHOW
        script = true
    [[baz]]
       script = sleep 10
    [[baz2]]
        inherit = None, SHOW
    [[<m>]]
        inherit = None, RESET, SHOW
    [[trigger]]
        inherit = None, SHOW
        script = cylc trigger ${CYLC_SUITE_NAME} baz.1; sleep 5
