farahats9 / sqlalchemy-celery-beat

Celery Periodic Tasks backed by the SQLAlchemy
MIT License
43 stars 6 forks source link

Crontab: hourly scheduled task executes every minute #12

Closed guidoiaquinti closed 2 months ago

guidoiaquinti commented 2 months ago

👋 Hi! I would like to report an issue where a task configured to run every hour at minute 0 is being executed every minute instead:

from celery.schedules import crontab

[...]

config = {
    "beat_schedule": {
        "run_every_hour": {
            "task": "tasks.run_every_hour",
            "schedule": crontab(hour="*", minute=0),
        },
    },
}
celery.conf.update(config)

[...]

It seems there might be an issue in translating the schedule to the database:

mysql> select * from celery_crontabschedule;
+----+--------+------+-------------+--------------+---------------+----------+
| id | minute | hour | day_of_week | day_of_month | month_of_year | timezone |
+----+--------+------+-------------+--------------+---------------+----------+
|  1 | 0      | 4    | *           | *            | *             | UTC      |
|  2 | *      | *    | *           | *            | *             | UTC      |
+----+--------+------+-------------+--------------+---------------+----------+
mysql> select * from celery_periodictask where task = 'tasks.run_every_hour'\G
*************************** 1. row ***************************
             id: 2
           name: run_every_hour
           task: tasks.run_every_hour
           args: []
         kwargs: {}
          queue: NULL
       exchange: NULL
    routing_key: NULL
        headers: {}
       priority: NULL
        expires: NULL
 expire_seconds: NULL
        one_off: 0
     start_time: NULL
        enabled: 1
    last_run_at: 2024-06-11 12:18:00
total_run_count: 3
   date_changed: 2024-06-11 12:18:30
    description:
  discriminator: crontabschedule
    schedule_id: 2
1 row in set (0.01 sec)

I'm using version v0.7.1 using SQLAlchemy 1.4 and MySQL as backend. Thanks!

farahats9 commented 2 months ago

Thank you for reporting this, pushing a fix shortly.