generated from TogetherCrew/python-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
28 lines (22 loc) · 835 Bytes
/
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
import logging
from rq import Worker
from utils.redis import RedisSingleton
def worker_exception_handler(job, exc_type, exc_value, traceback):
logging.error(" ========= RQ Exception =========")
logging.error(f"JOB: {job}")
logging.error(f"exc_type: {exc_type}")
logging.error(f"exc_value: {exc_value}")
logging.error(f"traceback: {traceback}")
if __name__ == "__main__":
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
r = RedisSingleton.get_instance().get_client()
worker = Worker(
queues=["default"], connection=r, exception_handlers=worker_exception_handler
)
logging.info("Registered the worker!")
try:
worker.work(with_scheduler=True, max_jobs=1)
except KeyboardInterrupt:
worker.clean_registries()
worker.stop_scheduler()