mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Code style check passed.
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scipt used to stop celery in AWS environments. This is used from upstart to issue a TERM signal to the master celery process.
|
Scipt used to stop celery in AWS environments.
|
||||||
|
This is used from upstart to issue a TERM signal to the master celery process.
|
||||||
|
|
||||||
This will then allow the worker threads to stop, after completing whatever tasks that are in flight.
|
This will then allow the worker threads to stop, after completing
|
||||||
|
whatever tasks that are in flight.
|
||||||
|
|
||||||
Note the script blocks for up to 15minutes, which is long enough to allow our longest possible task to complete. If it can return
|
Note the script blocks for up to 15minutes, which is long enough to allow our
|
||||||
quicker it will.
|
longest possible task to complete. If it can return quicker it will.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
./stop_celery.py <celery_pid_file>
|
./stop_celery.py <celery_pid_file>
|
||||||
@@ -21,9 +23,11 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
def strip_white_space(from_this):
|
def strip_white_space(from_this):
|
||||||
return re.sub(r'\s+', '', from_this)
|
return re.sub(r'\s+', '', from_this)
|
||||||
|
|
||||||
|
|
||||||
def get_pid_from_file(filename):
|
def get_pid_from_file(filename):
|
||||||
"""
|
"""
|
||||||
Open the file which MUST contain only the PID of the master celery process.
|
Open the file which MUST contain only the PID of the master celery process.
|
||||||
@@ -33,6 +37,7 @@ def get_pid_from_file(filename):
|
|||||||
celery_pid = f.read()
|
celery_pid = f.read()
|
||||||
return strip_white_space(celery_pid)
|
return strip_white_space(celery_pid)
|
||||||
|
|
||||||
|
|
||||||
def issue_term_signal_to_pid(pid):
|
def issue_term_signal_to_pid(pid):
|
||||||
"""
|
"""
|
||||||
Issues a TERM signal (15) to the master celery process.
|
Issues a TERM signal (15) to the master celery process.
|
||||||
@@ -45,6 +50,7 @@ def issue_term_signal_to_pid(pid):
|
|||||||
for line in result.stderr.readlines():
|
for line in result.stderr.readlines():
|
||||||
print(line.rstrip())
|
print(line.rstrip())
|
||||||
|
|
||||||
|
|
||||||
def pid_still_running(pid):
|
def pid_still_running(pid):
|
||||||
"""
|
"""
|
||||||
uses the proc filesystem to identify if the celery master pid is still around.
|
uses the proc filesystem to identify if the celery master pid is still around.
|
||||||
@@ -55,6 +61,7 @@ def pid_still_running(pid):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
arguments = docopt(__doc__)
|
arguments = docopt(__doc__)
|
||||||
celery_pid_file = arguments['<celery_pid_file>']
|
celery_pid_file = arguments['<celery_pid_file>']
|
||||||
|
|||||||
Reference in New Issue
Block a user