-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
44 lines (32 loc) · 1.07 KB
/
worker.py
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
""" Main entrypoint for the worker process """
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
os.environ.setdefault("ROLE", "worker")
import django
django.setup()
from django.conf import settings
from rq import SimpleWorker, Queue, Connection
from app.redis import conn
from okr.scrapers import scheduler as scheduler_okr
from bot_seo import scheduler as scheduler_bot_seo
scheduler_modules = [
scheduler_okr,
scheduler_bot_seo,
]
# Set up schedulers
for scheduler_module in scheduler_modules:
scheduler_module.setup()
if not settings.DEBUG:
scheduler_module.add_jobs()
# Start rq connection
listen = ["high", "default", "low"]
if __name__ == "__main__":
with Connection(conn):
worker = SimpleWorker(map(Queue, listen))
worker.work() # Blocking
# Cleanup
for scheduler_module in scheduler_modules:
scheduler_module.scheduler.shutdown()
if getattr(scheduler_module, "executors", None):
for executor in scheduler_module.executors.values():
executor.shutdown()