From 11df10f6f613a77c17262179ae3ce3c5c7246119 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Mon, 21 Mar 2022 19:38:04 -0600 Subject: [PATCH] dispatcher: Optionally exit when queue is empty Signed-off-by: Zack Cerza --- scripts/dispatcher.py | 3 ++- teuthology/dispatcher/__init__.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/dispatcher.py b/scripts/dispatcher.py index 8d955e48c3..4cb1abdea6 100644 --- a/scripts/dispatcher.py +++ b/scripts/dispatcher.py @@ -1,7 +1,7 @@ """ usage: teuthology-dispatcher --help teuthology-dispatcher --supervisor [-v] --bin-path BIN_PATH --job-config COFNFIG --archive-dir DIR - teuthology-dispatcher [-v] [--archive-dir DIR] --log-dir LOG_DIR --tube TUBE + teuthology-dispatcher [-v] [--archive-dir DIR] [--exit-on-empty-queue] --log-dir LOG_DIR --tube TUBE Start a dispatcher for the specified tube. Grab jobs from a beanstalk queue and run the teuthology tests they describe as subprocesses. The @@ -21,6 +21,7 @@ standard arguments: --supervisor run dispatcher in job supervisor mode --bin-path BIN_PATH teuthology bin path --job-config CONFIG file descriptor of job's config file + --exit-on-empty-queue if the queue is empty, exit """ import docopt diff --git a/teuthology/dispatcher/__init__.py b/teuthology/dispatcher/__init__.py index 5902f40353..9f7fa257e4 100644 --- a/teuthology/dispatcher/__init__.py +++ b/teuthology/dispatcher/__init__.py @@ -64,6 +64,7 @@ def main(args): tube = args["--tube"] log_dir = args["--log-dir"] archive_dir = args["--archive-dir"] + exit_on_empty_queue = args["--exit-on-empty-queue"] if archive_dir is None: archive_dir = teuth_config.archive_base @@ -103,13 +104,14 @@ def main(args): stop() load_config() - + job_procs = set(filter(lambda p: p.poll() is None, job_procs)) job = connection.reserve(timeout=60) if job is None: + if exit_on_empty_queue and not job_procs: + log.info("Queue is empty and no supervisor processes running; exiting!") + break continue - job_procs = set(filter(lambda p: p.poll() is None, job_procs)) - # bury the job so it won't be re-run if it fails job.bury() job_id = job.jid -- 2.39.5