#!/usr/bin/env bash
set -euo pipefail
WORKFLOW="$1"
OUT_FILE="$CYLC_WORKFLOW_RUN_DIR/file"
if grep -q -F '1' "${OUT_FILE}" 2>'/dev/null'; then
    echo '2' >>"${OUT_FILE}"
    cylc stop "${WORKFLOW}"
    exit 0
else
    echo '1' >"${OUT_FILE}"
    cylc stop --now --now "${WORKFLOW}"
    exit 1
fi
