如何使用 Celery 延迟任务?

发布于 2024-09-12 08:48:36 字数 112 浏览 2 评论 0原文

不谈论延迟方法。

我希望能够获取一个任务,给定它的 task_id 并在执行之前动态更改它的 ETA。

现在我必须取消它,并重新安排一个。如果预定的过程涉及很多事情,那就麻烦了。

Not talking about the delay method.

I want to be able to get a task, given it's task_id and change it's ETA on the fly, before it is executed.

For now I have to cancel it, and re-schedule one. Troublesome if the scheduled process involve a lot of stuff.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

病女 2024-09-19 08:48:36

您应该在芹菜/任务队列之外存储一些“暂停”值。我通过使用芹菜的邮件程序来完成此操作。我可以通过在 memcache 或 mysql 中设置值来暂停系统的某些部分。然后,任务确保在执行任务之前查询外部资源。如果它要暂停,它会设置它执行一个 task.retry() ,使其经历重试延迟时间等。

You should store some 'pause' value outside of celery/task queue. I do this with a mailer using celery. I can pause parts of the system by setting values in either memcache or mysql. The tasks then make sure to query the outside resource before executing the task. If it's meant to be paused it sets it does a task.retry() that causes it to go through the retry delay time and such.

破晓 2024-09-19 08:48:36

假设您将 django-celery 和 periodictask 与 DatabaseScheduler 一起使用,您需要修改 periodictask 间隔或 crontab 并保存它。如果您的任务是按时间间隔定义的,请修改 last_run_at 属性。

您可以使用数据库调度程序运行 celerybeat:

python manage.py celerybeat -S djcelery.schedulers.DatabaseScheduler

Assuming you are using django-celery and PeriodicTask with DatabaseScheduler, you need to modify your PeriodicTask interval or crontab and save it. If your task is defined by an interval, modify the last_run_at property.

You run celerybeat with the database scheduler with:

python manage.py celerybeat -S djcelery.schedulers.DatabaseScheduler
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文