Search code examples
python-3.xcroncelerycelerybeat

celery beat scheduler not scheduling tasks as expected using crontab


Celery beat is not scheduling tasks as expected using crontab. It schedules at random time. Sometimes it schedules every one minute once. Sometimes every two minutes once, etc. There is no relation between configured time "schedule": crontab(hour='*/1') and the time at which task is getting sent to worker!

No clue what's wrong here.

Here is my celery_test.py :

from kombu import Queue, Exchange
from celery import Celery, shared_task, group, chord
from celery.schedules import crontab

app = Celery('celery_demo',
             broker='amqp://abcduser:abcdpassword@localhost/abcd_vhost',
             backend='rpc://',
             include=['celery_demo.tasks'])

app.conf.beat_schedule = {
    "trigger-call_publisher": {
        "task": "celery_demo.tasks.call_publisher",
        "schedule": crontab(hour='*/1')

The below is my tasks.py :

import sys

sys.path.append("..")

from celery_demo.celery_test import app

@app.task
def call_publisher():
    print("Say Hello")

if __name__ == '__main__':
    call_publisher.delay()

    }
}

The below is one such output where the tasks are sent every minute once:

enter image description here


Solution

  • I think that dor making it run every hour you either use minute:

    crontab(minute='*/60')
    

    or hour + minute:

    crontab(minute=0, hour='*/1')