-
Notifications
You must be signed in to change notification settings - Fork 16
/
dramatiq
executable file
·74 lines (62 loc) · 1.9 KB
/
dramatiq
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import os
import importlib
from mist.api import config
BROKER = 'mist.api.dramatiq_app'
QUEUES = os.getenv('QUEUES', '').split(',') or [
'default',
'dramatiq_provisioning',
'dramatiq_scripts',
'dramatiq_schedules',
'dramatiq_rules',
'dramatiq_sessions',
'dramatiq_polling',
'dramatiq_mappings',
'dramatiq_ping_probe',
'dramatiq_ssh_probe',
'dramatiq_machines',
'dramatiq_clusters',
'dramatiq_networks',
'dramatiq_zones',
'dramatiq_volumes',
'dramatiq_secrets',
'dramatiq_buckets',
'dramatiq_tags']
POSSIBLE_MODULES = [] # 'mist.api.dramatiq_tasks', 'mist.rbac.dramatiq_tasks']
command = 'dramatiq'
processes = os.getenv('DRAMATIQ_PROCESSES')
if processes:
command += f' --processes {processes}'
threads = os.getenv('DRAMATIQ_THREADS')
if threads:
command += f' --threads {threads}'
for root, dirs, files in os.walk("src"):
for file in files:
if file.endswith('tasks.py'):
module = os.path.join(
root, file[:-3]).split('src/')[1].replace('/', '.')
POSSIBLE_MODULES.append(module)
print(module)
for root, dirs, files in os.walk("/opt"):
for file in files:
if file.endswith('tasks.py'):
print('.'.join(os.path.join(root, file[:-3]).split('/')[3:]))
modules = []
for module in POSSIBLE_MODULES:
try:
importlib.import_module(module)
except ModuleNotFoundError:
continue
modules.append(module)
print(f" * {module}")
for plugin in config.PLUGINS:
module = 'mist.' + plugin + '.tasks'
try:
importlib.import_module(module)
except ModuleNotFoundError:
continue
modules.append(module)
print(f" * {module}")
print(
f"Will execute command: {command} {BROKER} {' '.join(modules)} -Q {' '.join(QUEUES)}")
os.system(f"{command} {BROKER} {' '.join(modules)} -Q {' '.join(QUEUES)}")