Reputation: 20547
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
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