Reputation: 12361
I am in the process of upgrading to celery 5.x for a Django project. Since there is no longer a @scheduled_task
decorator, I changed all of those to @shared_task
and wrote some code to create CrontabSchedule
instances and associate PeriodicTask
instances with those for each task that should run on a schedule. I am invoking that from a beat_init
signal receiver. I'm running celery worker & beat as separate processes.
I am logging info from the function that sets up the CrontabSchedule
and PeriodicTask
instances, and I see that log output from the celery beat process. Immediately after that, I see a DatabaseScheduler:
Schedule changed." message. That's all as expected and good.
Subsequently, however, celery beat just sits and does nothing. beat never sends any messages, and as a result, celery worker never executes any scheduled tasks.
In django-admin shell_plus
, PeriodicTask.objects.all()
shows me many scheduled tasks with schedules that all look as they should. Here's 1 example from the output that should be running once per minute, every day:
<PeriodicTask: dhnetwork.tasks.send_queued_mail: {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59} {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23} * {1,2,3,4,5,6,7,8,9,10,11,12} {0,1,2,3,4,5,6} (m/h/dM/MY/d) America/Los_Angeles>
Any ideas what I might be doing wrong and/or how to diagnose the problem?
Upvotes: 0
Views: 391
Reputation: 12361
I found the problem. I was creating an instance of crontab
to validate values and then copying values from the properties of the crontab
instance to fields of the ``CrontabSchedule instance, but the properties of crontab
are set objects. When writing those values to string fields, we get the repr
of the set
as the values, and those are not valid.
In the all_as_schedule
method in schedulers.py, that results in a ValueError
which is caught and ignored, so the task is silently not added to the schedule.
Upvotes: 0