Skip to content

Instantly share code, notes, and snippets.

@GeorgeSabu
Last active March 31, 2020 10:30
Show Gist options
  • Save GeorgeSabu/4fbc359fa9ee2bf4d3cb05df3b60db81 to your computer and use it in GitHub Desktop.
Save GeorgeSabu/4fbc359fa9ee2bf4d3cb05df3b60db81 to your computer and use it in GitHub Desktop.
A example bash script which starts a job and waits till the job is complete
#!/bin/bash
# Starting a Polly job
# And this adds the output to a file called startme.txt
polly jobs submit --workspace-id <pass_workspace_id> --job-file $(pwd)/argojob.json > startme.txt
# Seeing the status
cat startme.txt
# checking if the job is been successfully submited ot not
# If error in submission exit with status 1
# If submitted successfully check the status of the job in regular intervals
SUCCESS_ERROR_INSTART=$(cat startme.txt | grep "Success:")
if [ "$SUCCESS_ERROR_INSTART" == "" ]; then
echo "Error occured while starting the job"
exit 1
else
echo "JOB launched"
fi
# Checking the status of the job at regular intervals
while [ true ]
do
# Getting the status command from the list of the commands that is given by the status
STATUS=$(cat startme.txt | grep "status" | cut -d : -f 2)
# excuting the command to check the status
$STATUS > status.txt
# showing the status
cat status.txt
# checking if the status is success or error
POLLY_SUCC=$(cat status.txt | grep "SUCCESS" || true)
POLLY_ERR=$(cat status.txt | grep "ERROR" || true)
#If not error showing message as running else exit with status 1
if [ "$POLLY_ERR" == "" ]; then
echo "RUNNING"
else
# On exit showing the logs
POLLY_LOGS=$(cat startme.txt | grep "logs" | cut -d : -f 2)
$POLLY_LOGS
echo "Error occured while running the job"
exit 1
fi
# If success exiting with status 0
if [ "$POLLY_SUCC" == "" ]; then
echo "RUNNING"
else
# On exit showing the logs
POLLY_LOGS=$(cat startme.txt | grep "logs" | cut -d : -f 2)
$POLLY_LOGS
echo "SUCCESS"
exit 0
fi
# If the job is running waiting for 10 seconds before next status check
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment