stop_celery_worker.py
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# OLD BASH SCRIPT
# ---------------
# (1) Empty only monitoring queue:
#celery -A pyros amqp queue.purge monitoring_q
# (2) Empty ALL queues
#celery -A pyros purge -f
# (3) THE HARD WAY : something like that...
#ps aux | grep \"celery worker\" | awk '{print $2}' | xargs kill -9
# NEW PYTHON SCRIPT
# -----------------
import subprocess
import sys
import platform
def main():
# if len(sys.argv) > 1:
#
# if sys.argv[1] == "--help":
# print("stop_celery_worker.py <arg>\n\t--all: purge all queue\n\t--hard: kill all celery worker "
# "\n\t--soft or no arg: purge monitoring queue (this is the standard way)\n\t--help:display this help")
# return True
# elif sys.argv[1] == "--all":
# p = subprocess.Popen("celery -A pyros purge -f", shell=True)
# elif sys.argv[1] == "--hard":
if platform.system() == 'Windows':
p = subprocess.Popen("taskkill /f /im celery.exe", shell=True)
else:
p = subprocess.Popen("ps aux | grep \"monitoring_q\" | awk '{print $2}' | xargs kill -9", shell=True)
# else:
# p = subprocess.Popen("celery -A pyros amqp queue.purge monitoring_q", shell=True)
p.wait()
# if (p.returncode != 0):
# print("ERROR !: Worker's launch failed\r\n", file=sys.stderr)
# return False
print("Workers stopped: OK")
return True
if __name__ == '__main__':
main()