From 826c7f541187717a1717312683fb7036cf04e7e7 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Wed, 18 Oct 2023 14:42:31 +0200 Subject: [PATCH] Add restart option pulpcore-worker [noissue] --- CHANGES/+pulpcore-worker-restart.feature | 1 + pulpcore/tasking/entrypoint.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 CHANGES/+pulpcore-worker-restart.feature diff --git a/CHANGES/+pulpcore-worker-restart.feature b/CHANGES/+pulpcore-worker-restart.feature new file mode 100644 index 0000000000..4ec3f43753 --- /dev/null +++ b/CHANGES/+pulpcore-worker-restart.feature @@ -0,0 +1 @@ +Added a ``--restart`` option to pulpcore worker. This requires "hupper" to be installed. diff --git a/pulpcore/tasking/entrypoint.py b/pulpcore/tasking/entrypoint.py index 95626255f4..06c8d207ff 100644 --- a/pulpcore/tasking/entrypoint.py +++ b/pulpcore/tasking/entrypoint.py @@ -18,10 +18,22 @@ @click.option( "--burst/--no-burst", help="Run in burst mode; terminate when no more tasks are available." ) +@click.option( + "--reload/--no-reload", help="Reload worker on code changes. [requires hupper to be installed.]" +) @click.command() -def worker(pid, burst): +def worker(pid, burst, reload): """A Pulp worker.""" + if reload: + try: + import hupper + except ImportError: + click.echo("Could not load hupper. This is needed to use --reload.", err=True) + exit(1) + + hupper.start_reloader(__name__ + ".worker") + if pid: with open(os.path.expanduser(pid), "w") as fp: fp.write(str(os.getpid()))