Reputation: 23
I have some logic in worker_process_init signal:
@worker_process_init.connect
def init_per_worker_publisher(**kwargs):
# some init logic...
If there appears unhandled exception, setup function is failed and no init happens but worker app keeps running like nothing happened.
I solved this problem like this:
@worker_process_init.connect
def init_per_worker_publisher(**kwargs):
try:
# some init logic...
except Exception:
celery_app.control.shutdown()
Maybe there is a better solution?
Upvotes: 2
Views: 442
Reputation: 36
You can raise a WorkerShutdown
exception.
from celery.exceptions import WorkerShutdown
@worker_process_init.connect
def init_per_worker_publisher(**kwargs):
try:
# some init logic...
except Exception:
raise WorkerShutdown()
Upvotes: 2