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()))