From ed1db863129a5fb17dcd02c47b8744458fa046e1 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Wed, 25 Nov 2020 10:45:14 -0800 Subject: Add olamic-wait tool for blocking until a task is complete. --- debian/olamic.install | 1 + man/olamic-enqueue.1.md | 4 ++-- man/olamic-wait.1.md | 23 +++++++++++++++++++++++ man/olamic-worker.1.md | 36 ------------------------------------ man/olamic-worker.8.md | 36 ++++++++++++++++++++++++++++++++++++ olamic-wait | 27 +++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 38 deletions(-) create mode 100644 man/olamic-wait.1.md delete mode 100644 man/olamic-worker.1.md create mode 100644 man/olamic-worker.8.md create mode 100755 olamic-wait diff --git a/debian/olamic.install b/debian/olamic.install index 6becfd7..d78041c 100644 --- a/debian/olamic.install +++ b/debian/olamic.install @@ -1,4 +1,5 @@ examples /usr/share/doc/olamic olamic-enqueue /usr/bin +olamic-wait /usr/bin olamic-worker /usr/bin pick-task /usr/share/olamic diff --git a/man/olamic-enqueue.1.md b/man/olamic-enqueue.1.md index 15434cc..b52c6ed 100644 --- a/man/olamic-enqueue.1.md +++ b/man/olamic-enqueue.1.md @@ -1,6 +1,6 @@ % OLAMIC-ENQUEUE(1) % Julian B Kongslie -% October 2020 +% November 2020 # NAME @@ -21,4 +21,4 @@ When **olamic-enqueue** completes, it prints the UUID of the created task. # SEE ALSO -olamic-worker(1) +olamic-wait(1), olamic-worker(1) diff --git a/man/olamic-wait.1.md b/man/olamic-wait.1.md new file mode 100644 index 0000000..6e9e769 --- /dev/null +++ b/man/olamic-wait.1.md @@ -0,0 +1,23 @@ +% OLAMIC-WAIT(1) +% Julian B Kongslie +% November 2020 + +# NAME + +olamic-wait - await completion of olamic task(s) + +# SYNOPSIS + +**olamic-wait** **/path/to/queue** **UUID** [**UUID** ...] + +# DESCRIPTION + +**olamic-wait** waits for the completion of the specified olamic tasks. You may +pass any number of UUIDs to it, and it will block until all those tasks have +been removed from the queue. + +While it is running, various status messages are written to stdout. + +# SEE ALSO + +olamic-enqueue(1) diff --git a/man/olamic-worker.1.md b/man/olamic-worker.1.md deleted file mode 100644 index d558f47..0000000 --- a/man/olamic-worker.1.md +++ /dev/null @@ -1,36 +0,0 @@ -% OLAMIC-WORKER(1) -% Julian B Kongslie -% October 2020 - -# NAME - -olamic-worker - run olamic tasks - -# SYNOPSIS - -**olamic-worker** - -# DESCRIPTION - -**olamic-worker** will continuously try to pull a new task from the olamic -queue, and run it. It uses its current working directory as a scratch space. - -# ENVIRONMENT VARIABLES - -**OLAMIC_EMAIL** -: The default email to complain to if a task fails. This can (and typically - will) be overridden on a per-task basis. - -**OLAMIC_QUEUE_HOST** -: The host where the olamic queue lives. Defaults to the local machine. - -**OLAMIC_QUEUE_DIR** -: The directory where the olamic queue lives. Defaults to /srv/olamic/queue. - -**OLAMIC_WORKER_PERIOD** -: How long the worker sleeps for when it can't find a task. Defaults to one - minute. - -# SEE ALSO - -olamic-enqueue(1) diff --git a/man/olamic-worker.8.md b/man/olamic-worker.8.md new file mode 100644 index 0000000..d558f47 --- /dev/null +++ b/man/olamic-worker.8.md @@ -0,0 +1,36 @@ +% OLAMIC-WORKER(1) +% Julian B Kongslie +% October 2020 + +# NAME + +olamic-worker - run olamic tasks + +# SYNOPSIS + +**olamic-worker** + +# DESCRIPTION + +**olamic-worker** will continuously try to pull a new task from the olamic +queue, and run it. It uses its current working directory as a scratch space. + +# ENVIRONMENT VARIABLES + +**OLAMIC_EMAIL** +: The default email to complain to if a task fails. This can (and typically + will) be overridden on a per-task basis. + +**OLAMIC_QUEUE_HOST** +: The host where the olamic queue lives. Defaults to the local machine. + +**OLAMIC_QUEUE_DIR** +: The directory where the olamic queue lives. Defaults to /srv/olamic/queue. + +**OLAMIC_WORKER_PERIOD** +: How long the worker sleeps for when it can't find a task. Defaults to one + minute. + +# SEE ALSO + +olamic-enqueue(1) diff --git a/olamic-wait b/olamic-wait new file mode 100755 index 0000000..557c80a --- /dev/null +++ b/olamic-wait @@ -0,0 +1,27 @@ +#!/bin/bash + +set -eu + +QUEUE_DIR="$1"; shift + +WAIT_UUID="" +while true; do + WAITING=false + for UUID in "$@"; do + if [[ -e "$QUEUE_DIR"/candidates/"$UUID" || -e "$QUEUE_DIR"/in-progress/"$UUID" ]]; then + WAITING=true + if [[ "$WAIT_UUID" != "$UUID" ]]; then + WAIT_UUID="$UUID" + echo "$(date -Iseconds) Waiting for: $UUID" + fi + break + else + echo "$(date -Iseconds) Complete: $UUID" + shift + fi + done + if ! $WAITING; then + break + fi + sleep 1 +done -- cgit v1.2.3