← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:add-dev-celery-startup-script into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:add-dev-celery-startup-script into launchpad:master.

Commit message:
Add script to start and stop celery workers in dev environments

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/402334

Use start-stop-daemon to start a celery worker (with configured concurrencies) for each current queue.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:add-dev-celery-startup-script into launchpad:master.
diff --git a/utilities/manage-celery-workers.sh b/utilities/manage-celery-workers.sh
new file mode 100755
index 0000000..1fb380a
--- /dev/null
+++ b/utilities/manage-celery-workers.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# Used for dev and dogfood, do not use in a production like environment.
+
+start_worker() {
+    # Start a worker for a given queue
+    queue=$1
+    echo "Starting worker for $queue"
+    start-stop-daemon \
+        --start --oknodo --quiet --background \
+        --pidfile "/var/tmp/celeryd-$queue.pid" --make-pidfile \
+        --startas "$PWD/bin/celery" -- worker \
+        --queues="$queue"\
+        --config=lp.services.job.celeryconfig \
+        --hostname="xenial-lpdev_dev_$queue" \
+        --loglevel=DEBUG \
+        --logfile="/var/tmp/celeryd-$queue.log"
+
+}
+
+stop_worker() {
+    queue=$1
+    echo "Stopping worker for $queue"
+    start-stop-daemon --stop --pidfile "/var/tmp/celeryd-$queue.pid"
+}
+
+case "$1" in
+  start)
+        for queue in launchpad_job launchpad_job_slow bzrsyncd_job bzrsyncd_job_slow branch_write_job branch_write_job_slow celerybeat
+        do
+            start_worker $queue
+        done
+        ;;
+  stop)
+        for queue in launchpad_job launchpad_job_slow bzrsyncd_job bzrsyncd_job_slow branch_write_job branch_write_job_slow celerybeat
+        do
+            stop_worker $queue
+        done
+        ;;
+
+  restart|force-reload)
+        for queue in launchpad_job launchpad_job_slow bzrsyncd_job bzrsyncd_job_slow branch_write_job branch_write_job_slow celerybeat
+        do
+            stop_worker $queue
+        done
+        sleep 1
+        for queue in launchpad_job launchpad_job_slow bzrsyncd_job bzrsyncd_job_slow branch_write_job branch_write_job_slow celerybeat
+        do
+            start_worker $queue
+        done
+        echo "$NAME."
+        ;;
+  *)
+        N=/etc/init.d/$NAME
+        echo "Usage: $N {start|stop|restart|force-reload}" >&2
+        exit 1
+        ;;
+esac