简体   繁体   English

celery celerybeat 可以在运行时动态添加/删除任务吗?

[英]Can celery celerybeat dynamically add/remove tasks in runtime?

I have a project that does not include Django, so i can't use djcelery.我有一个不包含 Django 的项目,所以我不能使用 djcelery。

But i found the modification of django-celery DatabaseSchedule that using sqlalchemy.但是我发现使用 sqlalchemy 对django-celery DatabaseSchedule进行了修改

It works fine as like djceley's DatabaseScheule did.它像 djceley 的 DatabaseScheule 一样工作正常。 But the only problem is that it doesn't seem to send tasks that were added in runtime, then i restart the celery-beat, the tasks that were added before will be sent successfully.但唯一的问题是它似乎没有发送运行时添加的任务,然后我重新启动celery-beat,之前添加的任务将成功发送。

So, is it possible to dynamically add/remove tasks without restarting celery-beat?那么,是否可以在不重新启动 celery-beat 的情况下动态添加/删除任务?

Thanks for any advice.感谢您的任何建议。 And sorry for my bad english.很抱歉我的英语不好。

Sorry, it was my fault.对不起,是我的错。 The tasks that were added in runtime will not be picked up instantly, you can change the DatabaseScheduler.sync_every value to a faster one.在运行时添加的任务不会立即被拾取,您可以将DatabaseScheduler.sync_every值更改为更快的值。 So it works after waiting for several minutes.所以它在等待几分钟后起作用。

Thanks for tuomur's help.感谢 tuomur 的帮助。

Solution 1:解决方案1:

I too had the same problem, The problem is, Celery periodic scheduler will look for [djcelery_periodictasks] which will have [last_update] value.我也遇到了同样的问题,问题是,Celery 定期调度程序将查找[djcelery_periodictasks]将具有[last_update]值。 If there is no change in the [last_update] then the celery will not check the [djcelery_periodictask] table.如果[last_update]没有变化,那么 celery 将不会检查[djcelery_periodictask]表。

What we have to do is, When ever you add/remove a task update the [last_update] time in [djcelery_periodictasks] .我们要做的是,当您添加/删除任务时,更新[djcelery_periodictasks][last_update]时间。

In my senario, I have the periodic scheduelr in python.在我的 senario 中,我在 python 中有定期调度程序。 However my Web UI is written in C#.但是我的 Web UI 是用 C# 编写的。 my web application will add/remove the entry in [djcelery_periodictask] and update the [last_update] time in [djcelery_periodictasks] .我的web应用程序将添加/删除条目[djcelery_periodictask]和更新[last_update]在时间[djcelery_periodictasks]

By this way, i have solved this issue.通过这种方式,我已经解决了这个问题。

When we use the standard flower UI, If we add/remove the task it will update the [last_update] time in [djcelery_periodictasks] .当我们使用标准flower UI 时,如果我们添加/删除任务,它将更新[djcelery_periodictasks][last_update]时间。 IF you have developed your own custom UI / application you have to include the functionality to update [last_update] time in [djcelery_periodictasks] to dynamically add/remove the task.如果您开发了自己的自定义 UI/应用程序,则必须包含更新[djcelery_periodictasks] [last_update]时间的功能,以动态添加/删除任务。

Solution2:解决方案2:

use flower : https://github.com/mher/flower使用花: https : //github.com/mher/flower

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

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