简体   繁体   English

celery 在工作模式下启动时的运行代码

[英]running code when celery starts in worker mode

I am looking to run some code when a celery worker starts.我希望在 celery 工作人员启动时运行一些代码。 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))

You are looking for worker signals ( https://docs.celeryproject.org/en/latest/userguide/signals.html?highlight=worker_ready#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.我猜worker_ready是你应该首先看的那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM