The Fool
The Fool

Reputation: 20547

running code when celery starts in worker mode

I am looking to run some code when a celery worker starts. Not when let's say a task is imported to be used from a client type application.

celery_app = Celery(__name__)
# I want to only create the egine if this file is used by a worker
engine = create_engine(str(POSTGRES_URL))

Upvotes: 0

Views: 870

Answers (1)

DejanLekic
DejanLekic

Reputation: 19822

You are looking for worker signals ( https://docs.celeryproject.org/en/latest/userguide/signals.html?highlight=worker_ready#worker-signals ). It is all nicely explained there. I am guessing worker_ready is the one you should look at first.

Upvotes: 1

Related Questions