Skip to content

Instantly share code, notes, and snippets.

@Kuchitama
Created December 10, 2019 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kuchitama/199d91852614a0ba79a79a3d6514b70d to your computer and use it in GitHub Desktop.
Save Kuchitama/199d91852614a0ba79a79a3d6514b70d to your computer and use it in GitHub Desktop.
digdag scripts
#!/bin/bash
DIGDAG=~/bin/digdag
# see https://github.com/treasure-data/digdag/blob/v0.9.27/digdag-cli/src/main/java/io/digdag/cli/client/ShowAttempts.java#L83-L95
last_result=$($DIGDAG attempts 2>&1 | tail -13);
if [[ $last_result =~ ^.+attempt[[:space:]]id:[[:space:]]([0-9]+).+$ ]];
then
attempt_id=${BASH_REMATCH[1]};
if [ -z $attempt_id ]; then
echo "Cannot find attempt_id" >&2;
exit 1;
fi
fi
if [[ $last_result =~ ^.+status:[[:space:]]+(error|success|running)[[:space:]]*+$ ]];
then
status=${BASH_REMATCH[1]};
if [ -z $status ]; then
echo "Cannot find status" >&2;
exit 1;
fi
if [ $status = 'running' -o $status = 'success' ]; then
echo "Cannot resume last attempt[${attempt_id}]. Its status is '${status}'" >&2;
exit 1;
fi
else
echo "cannnot find status"
exit 1;
fi
$DIGDAG retry ${attempt_id} --latest-revision --resume
#!/bin/bash
DIGDAG=~/bin/digdag
# see https://github.com/treasure-data/digdag/blob/v0.9.27/digdag-cli/src/main/java/io/digdag/cli/client/ShowAttempts.java#L83-L95
status=$($DIGDAG attempts 2>&1 | tail -13 | grep 'status' | awk '{print $2}');
if [[ $status =~ ^(error|success|running)$ ]]; then
echo $status;
if [ $status = 'error' ]; then
exit 2;
fi
else
echo "Invalid status found: ${status}" >&2;
exit 2;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment