【问题标题】:Schedule Django Celery periodic tasks to run from time to other time安排 Django Celery 定期任务从某个时间运行到另一个时间
【发布时间】:2017-09-25 21:47:53
【问题描述】:

我如何才能完成运行 Django Celery 任务,使其仅在周一至周五运行,并且在那些日子仅从美国东部标准时间上午 9 点到下午 5 点运行?

celery.py

from celery.schedule import crontab


app.conf.beat_schedule = {
    'compute-every-5-seconds': {
         'task': 'sum',
         'schedule': crontab(),
     },
  }

我应该向 crontab() 添加哪些参数以使其在那些日子和仅在这些时间之间运行?

【问题讨论】:

    标签: django cron celery django-celery periodic-task


    【解决方案1】:

    celery.py

    from celery.schedule import crontab
    app.conf.beat_schedule = {
        'compute-every-minute-mon-through-friday-9-to-5': {
             'task': 'sum',
             'schedule': crontab(minute='*/1',
    hour='9-17', day_of_week='mon,tue,wed,thu,fri'),
         },
      }
    

    minute='*/1' - 每分钟运行一次

    hour='9-17' - 上午 9 点到下午 5 点运行

    day_of_week='mon,tue,wed,thu,fri' - 周一至周五

    其中大部分都可以在documentation 页面上找到,请查看!

    【讨论】:

      猜你喜欢
      • 2011-12-12
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 2015-01-04
      • 2021-02-05
      • 2019-09-29
      • 2018-09-09
      相关资源
      最近更新 更多