Blame view

src/monitoring/stop_celery_worker.py 1.42 KB
64a7b593   Quentin Durand   creating start an...
1
2
#!/usr/bin/env python3

678d4a06   Etienne Pallier   New (python, mult...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# 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
# -----------------

64a7b593   Quentin Durand   creating start an...
21
22
import subprocess
import sys
fdf96ee0   Quentin Durand   Trying to make st...
23
import platform
64a7b593   Quentin Durand   creating start an...
24

64a7b593   Quentin Durand   creating start an...
25
26
27
28
29
30
31
32
33
34
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":
fdf96ee0   Quentin Durand   Trying to make st...
35
36
37
38
    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)
64a7b593   Quentin Durand   creating start an...
39
40
41
42
43
44
45
46
47
48
49
    # 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()