【问题标题】:How to schedule weekday-aware jobs in celery如何在 celery 中安排工作日感知工作
【发布时间】:2013-02-05 21:17:31
【问题描述】:

是否可以使用 celery beat 配置复杂的时间表?例如,像这样:

在周一至周五,使用参数 (x1, y1) 执行作业 A,然后执行作业 B 周六、周日,用参数(x2, y2)做作业A,不做作业B

我知道我可以实现一个高频“tick”任务来检查这个时间表,但如果已经存在这样的东西,我不想重新发明轮子。

【问题讨论】:

    标签: python django celery django-celery celerybeat


    【解决方案1】:

    当然,为您的任务使用crontab schedule。

    from celery.schedules import crontab
    
    CELERYBEAT_SCHEDULE = {
        # Executes every weekday morning at 7:30 A.M
        'weekdays': {
            'task': 'tasks.A',
            'schedule': crontab(hour=7, minute=30, day_of_week='1-5'),
            'args': (x1, y1),
        },
        # Executes saturday morning at 4:00 A.M
        'saturday': {
            'task': 'tasks.B',
            'schedule': crontab(hour=7, minute=30, day_of_week='sat'),
            'args': (x1, y1),
        },
        # Executes sunday morning at 2:15 A.M
        'sunday': {
            'task': 'tasks.A',
            'schedule': crontab(hour=2, minute=15, day_of_week='sun'),
            'args': (x2, y2),
        },
    }
    

    【讨论】:

    • 是与操作系统 crontab 相关,还是与 celerybeat 相关?
    • @Goro:这是一个 Celery 提供的类。
    猜你喜欢
    • 2012-09-10
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 2021-10-18
    相关资源
    最近更新 更多