celery / django-celery-beat

Celery Periodic Tasks backed by the Django ORM
Other
1.69k stars 428 forks source link

How to update PeriodicTask after updating tasks in `app.conf.beat_schedule` #757

Open jlariza opened 4 months ago

jlariza commented 4 months ago

Summary:

Good day,

I've noticed that PeriodicTask instances are not updated after app.conf.beat_schedule is updated. For example, this is my original app.conf.beat_schedule:

app.conf.beat_schedule = {
    "send-pending-messages": {
        "task": "app.messages.tasks.send_pending_pessages",
        "schedule": crontab(hour=6, minute=0, day_of_month="25"),
    },
}

It creates a PeriodicTask with this crontab: 0 6 25 * * (m/h/dM/MY/d).

Then, after some changes in my code, I update the beat_schedule to

app.conf.beat_schedule = {
    "send-pending-messages": {
        "task": "app.messages.tasks.send_pending_pessages",
        "schedule": crontab(hour=5, minute=0, day_of_month="10"),
    },
}

However, after this change, the PeriodicTask is still with this crontab: 0 6 25 * * (m/h/dM/MY/d) when it should be 0 5 10 * * (m/h/dM/MY/d).

How may I make sure that the database will be updated if I modified the app.conf.beat_schedule configuration?

Thank you,

jlariza commented 4 months ago

At the end, I had to delete the PeriodicTask instances from the database and restart the app to force it to create the new ones correctly.

However, it would be nice to have a mechanism to force a database refresh without having to delete the database (specially in the cases where not all PeriodicTask are saved in the beat_schedule. Also, it would solve the problem with the deleted tasks reported in https://github.com/celery/django-celery-beat/issues/706

Thank you,

m-r-k-f commented 3 months ago

Hi jlariza, I had the same issue. But I fount a good solution: #768 Have fun.

kylebebak commented 3 months ago

This is really basic functionality -- if the records in django_celery_beat_periodictask (the DB) don't match what's in beat_schedule (application code), this library is broken