【问题标题】:Restarting celery and celery beat schedule relationship in django在 django 中重启 celery 和 celery beat schedule 关系
【发布时间】:2021-12-01 14:12:39
【问题描述】:

重启 celery 是否会导致所有周期性任务(celery beat schedules)重置并从 celery 重启时开始,还是保留时间表?

例如,假设我有一个定期任务,每天下午 12 点执行。现在我在下午 3 点重新启动 celery。定期任务会重置为每天下午 3 点运行吗?

【问题讨论】:

    标签: django celery django-celery


    【解决方案1】:

    你如何设置你的任务?

    这里是many ways设置任务计划→

    • Example:每 30 秒运行一次 tasks.add 任务。
    app.conf.beat_schedule = {
        'add-every-30-seconds': {
            'task': 'tasks.add',
            'schedule': 30.0,
            'args': (16, 16)
        },
    }
    app.conf.timezone = 'UTC'
    

    此任务在启动后每 30 秒运行一次。

    • 另一个例子:
    from celery.schedules import crontab
    
    app.conf.beat_schedule = {
        # Executes every Monday morning at 7:30 a.m.
        'add-every-monday-morning': {
            'task': 'tasks.add',
            'schedule': crontab(hour=7, minute=30),
            'args': (16, 16),
        },
    }
    

    此任务每天 7:30 运行。

    您可以查看schedule examples

    所以答案取决于你的代码。

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 2015-01-01
      • 2022-01-20
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      相关资源
      最近更新 更多