简体   繁体   English

用动态源(数据库)替换Celery Beat“ CELERYBEAT_SCHEDULE”

[英]Replacing Celery Beat “CELERYBEAT_SCHEDULE” with a dynamic source (database)

In the Celery docs , the standard way to set the schedule of tasks is documented as hardcoding the schedule into the config file. Celery文档中 ,记录任务时间表的标准方法记录为将时间表硬编码到配置文件中。

However, it also hints that this can be replaced with a custom backend. 但是,这也暗示可以将其替换为自定义后端。 I see there is a dynamic, database driven option for Django but I'm using a simple Flask app to define my tasks. 我看到Django有一个动态的数据库驱动选项,但我使用的是简单的Flask应用程序来定义任务。

Does anyone have a way to dynamically load the schedule, avoiding the need to restart the celery beat worker, either by dynamically pulling the schedule from a database or by reloading the schedule from a text file on a regular basis? 是否有人可以通过动态从数据库中拉出时间表或定期从文本文件中重新加载时间表来动态加载时间表,而无需重启芹菜节拍工作器呢? Is it as simple as putting a reload() call around the schedule in a text file, perhaps even as its own scheduled celery task? 是否像在日程表中将reload()调用放在文本文件中一样简单,甚至与其自己的预定芹菜任务一样简单?

CELERYBEAT_SCHEDULE is just init/config sugar and the object is available from within a bound task at: CELERYBEAT_SCHEDULE只是init / config的糖,该对象可从绑定的任务中找到:

self.app.conf['CELERYBEAT_SCHEDULE']

You might write a periodic task that pulls down new values from some back end. 您可能编写了一个定期任务,该任务从某个后端提取新值。

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

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