Description
Summary:
I had the (obviously now incorrect) assumption that if I used celery_beat
in the celery config dictionary to define my schedule that if I changed it (renamed or removed items) that the database schedule would be synced to the removals.
I don't expect this issue to be fixed -- I'm just documenting it for other people looking for an answer.
- Celery Version: 4.2.1
- Celery-Beat Version: 1.1.1
Exact steps to reproduce the issue:
- Configure
celery_beat
in config - Run beat
- Remove some tasks/add some tasks to
celery_beat
- Rerun beat
Detailed information
I've documented a work around here, creating my own scheduler:
https://stackoverflow.com/q/56047284/2077386
import logging
from django_celery_beat.models import PeriodicTask
from django_celery_beat.models import PeriodicTasks
from django_celery_beat.schedulers import DatabaseScheduler
from django.db import transaction
class DatabaseSchedulerWithCleanup(DatabaseScheduler):
def setup_schedule(self):
schedule = self.app.conf.beat_schedule
with transaction.atomic():
num, info = PeriodicTask.objects.\
exclude(task__startswith='celery.').\
exclude(name__in=schedule.keys()).\
delete()
logging.info("Removed %d obsolete periodic tasks.", num)
if num > 0:
PeriodicTasks.update_changed()
super(DatabaseSchedulerWithCleanup, self).setup_schedule()
I'm posting it here for anyone else to use -- and in case you want to add it to the project.
This scheduler assumes you are using celery_beat
in your celery config exclusively to define your schedule as it would wipe out any tasks not included in there. It could theoretically wipe out tasks from other apps (see above I whitelist celery.*).
So.... I don't think it's actually a great candidate for the project.