Skip to content

Instantly share code, notes, and snippets.

@EvanTheB
Last active April 26, 2019 06:51
Show Gist options
  • Save EvanTheB/8f9e07746af0c84831fc17f94ac4672d to your computer and use it in GitHub Desktop.
Save EvanTheB/8f9e07746af0c84831fc17f94ac4672d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
CACHE_FILE="$HOME"/.cache/qstat.map
# a 1 minute timed cache
# does not actually handle failures properly. todo
if ! test -e $CACHE_FILE || (( $(find "$CACHE_FILE" -mmin +1 | wc -l) > 0)); then
CACHE_FILE_TMP="$CACHE_FILE.$$.$RANDOM"
trap 'rm '"$CACHE_FILE_TMP" EXIT
qstat | awk '$3 ~ /cromwell/{print $1}' > "$CACHE_FILE_TMP"
mv "$CACHE_FILE_TMP" "$CACHE_FILE"
trap '' EXIT
fi
grep -q '^'"$1"'$' "$CACHE_FILE"
@EvanTheB
Copy link
Author

I just realised this wont deal with brand new jobs very well - need the cache duraction to be shorter than the check-alive interval. (and hope check-alive is called AFTER an interval, not straight after qsub)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment