mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 07:37:08 +00:00
Add tasks runner script.
This script runs the deferred imports. It is meant to be called from a cronjob at regular intervals – every one or two minutes is probably a good setting. It checks if another instance is already running before doing its thing. If anything goes wrong (any of the called processes exits with non-zero condition) it will send an alert to GitLab, provided that the authorisation key is known.
This commit is contained in:
98
bin/runner.sh
Executable file
98
bin/runner.sh
Executable file
@@ -0,0 +1,98 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DOUGAL_ROOT=${DOUGAL_ROOT:-$(dirname "$0")/..}
|
||||||
|
|
||||||
|
BINDIR="$DOUGAL_ROOT/bin"
|
||||||
|
VARDIR=${VARDIR:-$DOUGAL_ROOT/var}
|
||||||
|
LOCKFILE=${LOCKFILE:-$VARDIR/runner.lock}
|
||||||
|
|
||||||
|
function tstamp () {
|
||||||
|
date -u +%Y-%m-%dT%H:%M:%SZ
|
||||||
|
}
|
||||||
|
|
||||||
|
function prefix () {
|
||||||
|
printf "\033[30;1m$(tstamp)\t"
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_log () {
|
||||||
|
printf "$(prefix)\033[36m%s\033[0m\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_info () {
|
||||||
|
printf "$(prefix)\033[0m%s\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_warning () {
|
||||||
|
printf "$(prefix)\033[33;1m%s\033[0m\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_error () {
|
||||||
|
printf "$(prefix)\033[31m%s\033[0m\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
function run () {
|
||||||
|
PROGNAME=$(basename "$1")
|
||||||
|
STDOUTLOG="$VARDIR/$PROGNAME.out"
|
||||||
|
STDERRLOG="$VARDIR/$PROGNAME.err"
|
||||||
|
|
||||||
|
"$1" >"$STDOUTLOG" 2>"$STDERRLOG" || {
|
||||||
|
print_error "Failed: $PROGNAME"
|
||||||
|
cat $STDOUTLOG
|
||||||
|
cat $STDERRLOG
|
||||||
|
|
||||||
|
print_warning "Sending alert (if configured)"
|
||||||
|
TITLE="$PROGNAME failed"
|
||||||
|
# DESCRIPTION=""
|
||||||
|
SERVICE="deferred_imports"
|
||||||
|
|
||||||
|
$BINDIR/send_alert.py -t "$TITLE" -s "$SERVICE" -l "critical" \
|
||||||
|
-O "$(cat $STDOUTLOG)" -E "$(cat $STDERRLOG)"
|
||||||
|
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
# cat $STDOUTLOG
|
||||||
|
|
||||||
|
rm $STDOUTLOG $STDERRLOG
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -f $LOCKFILE ]]; then
|
||||||
|
PID=$(cat "$LOCKFILE")
|
||||||
|
if pgrep -F "$LOCKFILE"; then
|
||||||
|
print_warning $(printf "The previous process is still running (%d)" $PID)
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
rm "$LOCKFILE"
|
||||||
|
print_warning $(printf "Previous process (%d) not found. Must have died unexpectedly" $PID)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$$" > "$LOCKFILE" || {
|
||||||
|
print_error "Error creating lock file"
|
||||||
|
exit 255
|
||||||
|
}
|
||||||
|
print_info "Start run"
|
||||||
|
|
||||||
|
print_log "Purge deleted files"
|
||||||
|
run $BINDIR/purge_deleted_files.py
|
||||||
|
|
||||||
|
print_log "Import survey configurations"
|
||||||
|
run $BINDIR/import_survey_config.py
|
||||||
|
|
||||||
|
print_log "Import preplots"
|
||||||
|
run $BINDIR/import_preplots.py
|
||||||
|
|
||||||
|
print_log "Import raw P1/11"
|
||||||
|
run $BINDIR/import_raw_p111.py
|
||||||
|
|
||||||
|
print_log "Import raw P1/90"
|
||||||
|
run $BINDIR/import_raw_p190.py
|
||||||
|
|
||||||
|
print_log "Import final P1/11"
|
||||||
|
run $BINDIR/import_final_p111.py
|
||||||
|
|
||||||
|
print_log "Import final P1/90"
|
||||||
|
run $BINDIR/import_final_p190.py
|
||||||
|
|
||||||
|
|
||||||
|
rm "$LOCKFILE"
|
||||||
|
print_info "End run"
|
||||||
3
var/README.md
Normal file
3
var/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Varying data directory
|
||||||
|
|
||||||
|
This is used for storage of temporary data files such as those produced by [`/bin/runner.sh`](../bin/runner.sh) and must therefore be writable by the Dougal user.
|
||||||
Reference in New Issue
Block a user