mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-11 15:52:21 -05:00
Stopping celery via upstart issues a TERM signal to the whole process group, which immediately kills the worker threads. This can lead to inconsistentcy in the state of a notification as an API call, for example, can take several seconds consequently the likelihood of the call being lost due to a restart is relatively high.
We need to ensure that we stop cleanly to ensure code deploys and autoscale events do not cause issues.
this script is called as part of a pre-stop hook in upstart, which passes a pid file location to the script. The script will then issues the TERM signal to only the master celery process. which will cleanly shut down the workers and exit.
the script will loop based on the existence of a /proc/{pid} for the celery master process. Once the file is gone the script will exit. Upstart blocks on this script before issuing kill on whatever processes may be left hanging around.
the length of the loop is a maximum 15 minutes - which is the tested max time a task may take. In reality it will exit much quicker.
7 lines
145 B
Bash
Executable File
7 lines
145 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
source environment.sh
|
|
celery -A run_celery.notify_celery worker --pidfile="/tmp/celery.pid" --loglevel=INFO --concurrency=4
|