How to log when SIGTERM is received by a worker #2064
-
Is there better way of logging when SIGTERM received by a worker then following? This feels like low level programming. If there is a function i can attach that runs before stopping worker. import signal
import logging
def handle_sigterm(signum, frame):
logging.warning('Received SIGTERM, shutting down worker')
worker.request_stop(signum, frame)
signal.signal(signal.SIGTERM, handle_sigterm)
worker = rq.Worker('my-queue')
worker.work() |
Beta Was this translation helpful? Give feedback.
Answered by
karunpoudel-chr
Mar 26, 2024
Replies: 1 comment
-
I think I found the solution: We can simply override it in child class: class MyWorker(rq.Worker):
def handle_warm_shutdown_request(self):
logger.info("My custom handler")
worker = MyWorker('my-queue')
worker.work() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
karunpoudel-chr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I found the solution:
Worker.handle_warm_shutdown_request()
function logs infolog.info('Warm shut down requested')
.We can simply override it in child class: