Reputation: 2551
I've been looking over the Celery 4.3.0 documentation, but I can't find any kind lifecycle events for workers. Most of the worker management is command line based, but I need a way to hook a worker start event in code so I can do some customized queue consumer assignments.
Does Celery have such events?
Upvotes: 2
Views: 1243
Reputation: 29594
Celery dispatches signals on various events. There are 2 signals related to worker init
worker_init
signal which is dispatched before the worker is started.
worker_process_init
signal which is dispatched in all pool child processes when they start.
Here is a sample to code to listen to signals.
from celery.signals import worker_init, worker_process_init
@worker_init.connect()
def worker_init_handler(*args, **kwargs):
print(args, kwargs)
print('worker_init')
@worker_process_init.connect()
def worker_process_init_handler(*args, **kwargs):
print(args, kwargs)
print('worker_process_init')
Upvotes: 5