Celerybeat 同一任务的多个计划

发布于 2025-01-15 05:14:56 字数 504 浏览 5 评论 0原文

我收到了以下 Celery 节拍任务,每天凌晨 1 点清理 1000 件物品:

from celery.schedules import crontab
from .celery import app as celery_app

celery_app.conf.beat_schedule['maintenance'] = {
        'task': 'my_app.tasks.maintenance',
        'schedule': crontab(hour=1, minute=0),
        'args': (1000,)
    }

我想每周日下午 5 点额外清理 5000 件物品。有没有办法添加第二个时间表?

        'schedule': crontab(hour=17, minute=0, day_of_week='sunday'),
        'args': (5000,)

以及如何确保它们不会重叠?

I got following Celery beat task which cleans 1000 items daily at 1 AM:

from celery.schedules import crontab
from .celery import app as celery_app

celery_app.conf.beat_schedule['maintenance'] = {
        'task': 'my_app.tasks.maintenance',
        'schedule': crontab(hour=1, minute=0),
        'args': (1000,)
    }

I want to clean additional 5000 items every Sunday at 5PM. Is there a way to add second schedule?

        'schedule': crontab(hour=17, minute=0, day_of_week='sunday'),
        'args': (5000,)

And how to ensure they won't overlap?

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

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

发布评论

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

评论(1

救赎№ 2025-01-22 05:14:56

任务 1 将每天运行,包括周日,任务 2 将仅在周日运行

  app.conf.beat_schedule = {
        'task1':{
            'task':'my_app.tasks.maintenance',
            'schedule': crontab(hour=1, minute=0),
            'args': (1000,)
        },
        'task2':{
            'task':'my_app.tasks.maintenance',
            'schedule': crontab(minute=00, hour=17, day_of_week='sunday'),
            'args': (5000,)
        },
   }

Task1 will run every day including sunday and Task 2 will run only on sunday

  app.conf.beat_schedule = {
        'task1':{
            'task':'my_app.tasks.maintenance',
            'schedule': crontab(hour=1, minute=0),
            'args': (1000,)
        },
        'task2':{
            'task':'my_app.tasks.maintenance',
            'schedule': crontab(minute=00, hour=17, day_of_week='sunday'),
            'args': (5000,)
        },
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文