Repository navigation
Description
I happened to install celery 4.1.0 with django_celey_beat 1.0.1, the DatabaseScheduler seems not working well.
[2017-08-07 21:12:10,790: DEBUG/MainProcess] DatabaseScheduler: Fetching database schedule
[2017-08-07 21:12:10,797: DEBUG/MainProcess] Current schedule:
<ModelEntry: celery.backend_cleanup celery.backend_cleanup([], **{}) <crontab: 0 4 * * * (m/h/d/dM/MY)>>
<ModelEntry: schedule GeneBank.tasks.test([], **{}) <crontab: * * * * * (m/h/d/dM/MY)>>
[2017-08-07 21:12:10,807: DEBUG/MainProcess] beat: Ticking with max interval->5.00 seconds
[2017-08-07 21:12:10,809: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:15,813: DEBUG/MainProcess] beat: Synchronizing schedule...
[2017-08-07 21:12:15,813: INFO/MainProcess] Writing entries...
[2017-08-07 21:12:15,816: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:20,818: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:25,825: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:30,831: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:35,839: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:40,844: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:45,851: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:50,854: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:12:55,860: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:13:00,862: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:13:05,870: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
^C[2017-08-07 21:13:10,245: INFO/MainProcess] Writing entries...
[2017-08-07 21:13:10,246: INFO/MainProcess] Writing entries...
As u can see, the scheduler was supposed to send beat at every minute, but the beat didn't show up, (i've set crontab to be all *, so couldn't be timezone problem)
But in celery 4.0.2, everything goes fine! I don't know whether it is a bug or not. Maybe the django_celery_beat isn't compatible with 4.1.0.
[2017-08-07 21:18:43,339: DEBUG/MainProcess] Current schedule:
<ModelEntry: celery.backend_cleanup celery.backend_cleanup([], **{}) <crontab: 0 4 * * * (m/h/d/dM/MY)>>
<ModelEntry: schedule GeneBank.tasks.test([], **{}) <crontab: * * * * * (m/h/d/dM/MY)>>
[2017-08-07 21:18:43,351: DEBUG/MainProcess] beat: Ticking with max interval->5.00 seconds
[2017-08-07 21:18:43,364: INFO/MainProcess] Scheduler: Sending due task schedule (GeneBank.tasks.test)
[2017-08-07 21:18:43,376: DEBUG/MainProcess] beat: Synchronizing schedule...
[2017-08-07 21:18:43,376: INFO/MainProcess] Writing entries...
[2017-08-07 21:18:43,380: DEBUG/MainProcess] GeneBank.tasks.test sent. id->9c1bdf10-0a5f-440a-98db-9eb24433a8d4
[2017-08-07 21:18:43,381: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:18:48,386: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:18:53,392: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2017-08-07 21:18:58,397: DEBUG/MainProcess] beat: Waking up in 1.59 seconds.
[2017-08-07 21:19:00,001: INFO/MainProcess] Scheduler: Sending due task schedule (GeneBank.tasks.test)
Activity
codeadict commentedon Aug 8, 2017
I'm using both and they are working just fine
gray314 commentedon Aug 9, 2017
after updating to version 4.1.0 from version 4.0.2 - got a similar error, the task scheduler does not work properly
rekale commentedon Aug 9, 2017
same here, when I downgrade to 4.0.2 it works again.
rekale commentedon Aug 10, 2017
I think this bug is related with timezone, when I change the timezone to UTC it works.
CELERY_TIMEZONE = 'UTC'
CELERY_ENABLE_UTC = True
georgepsarakis commentedon Aug 10, 2017
Could you please re-check with current
masterbranch?AyumuKasuga commentedon Aug 15, 2017
I can confirm this bug in 4.1.0
in my settings:
And yes it works fine with:
matteius commentedon Aug 18, 2017
Same issue -- we have multiple projects using celery beat but one of them happened to set the CELERY_TIMEZONE to be the project timezone which was America/NewYork. Literally I woke up with 18 million messages in the Rabbit QA server because the workers couldn't keep up with the rate they are enqueued -- hundreds a minute. Deleting the settings and letting the project default to CELERY_TIMEZONE of None also resolved the issue.
matteius commentedon Aug 18, 2017
FWIW -- I don't think we are using the DatabaseScheduler. Maybe the issue name should be renamed?
georgepsarakis commentedon Aug 19, 2017
@matteius @AyumuKasuga if you can run a test with the
masterbranch to verify the fix, it would be great. Sorry for the issues.AyumuKasuga commentedon Aug 22, 2017
Hello @georgepsarakis !
I have just tested master branch and unfortunately in my setup the issue is still exists.
117111302 commentedon Aug 24, 2017
Same here!
gehaxelt commentedon Aug 28, 2017
Hi,
I have a similar problem. I followed the django-celery-beat setup instructions from: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html
Then I define a periodic task:
When starting celery beat, I get the following output:
The periodic task exists in the database and is marked as
enabled.However, a celery worker does not receive or execute any periodic tasks:
Software:
Any ideas/help to resolving this issue is welcomed.
Best,
Sebastian
mchen-scala commentedon Oct 3, 2017
A piece of shit. It doesn't work.
codeadict commentedon Oct 3, 2017
@mchen-scala I think OSS projects are for collaborating and objective and constructive critics. How many lines of codes have you put in the piece of shit? I actually have Celery with beat working perfectly.
mchen-scala commentedon Oct 3, 2017
I have built far more advanced systems than you will ever have. I have written operating systems and built high-frequency trading platforms and large-scale cross-datacenter DBs. And many more.
Lines of code? I only look at systems that WORK. LOC is for tyros.
I have to use Celery because the system I inherited uses it. I am going to get rid of it and write my own once we are done our first delivery.
In addition to the beat problem, asking people to use a lock to ensure at-most-once property in task execution is a GIGANTIC JOKE.
Stick to what you are good at, which is OSS since you can't get high-paying jobs.
1 remaining item
matteius commentedon Oct 12, 2017
I have pin-pointed the exact line of code that is converting my already timezone aware datetime to a future datetime in an offset +20 that I am sure isn't a real timezone offset.
2017-10-11 22:42:27.041931-04:00 gets converted to 2017-10-12 22:42:27.041931+20:00 at the line in my Pull Request.
Apparently in UTC mode the datetime object stays the same at this point in the code. So what happens next is the result of remaining_delta is interpreted as being -1 day, 1:27:32.958069 behind the task schedule. So it sends out the task and doesn't sleep long because its always behind. It just keeps beating out the tasks, always becuase its -1 days until the task is due.
Granted my PR is commenting out a real old line of code, and yet all the unit tests seemed to pass and it did solve this issue in my testing. Looking from collaborator feedback.
matteius commentedon Oct 15, 2017
I have shown this to be an issue on Python 2.7 as well as Python 3.5 and 3.6 versions. Not to say it isn't a bug in other versions, those are just ones I set up environments with.
xeor commentedon Oct 20, 2017
I tried to migrate from not using the database for beat, to using django-celery-beat... The day have been mostly reading github issues :(
Is there anyone else not getting this to work when using
CELERY_TIMEZONE = 'UTC'? I'm having problems getting it to work with that set as well..matteius commentedon Oct 20, 2017
@xeor You may also need to be setting CELERY_ENABLE_UTC = True
The actual issue of the datetime being passed into localize() is that if you have a local not UTC timezone set for your project, then that datetime already is correct going into localize and then dt = dt.astimezone(tz) transforms that into a non-nonsensical future datetime with a timezone that makes no sense.
fillipo commentedon Oct 20, 2017
@xeor I was having the same issue even with the following settings:
Now, I know it seems silly, but I uninstalled both Celery and django-celery-beat, and installed them again with their latest version and it worked.
xeor commentedon Oct 20, 2017
Thanks.. I have tried with all those 3 as well, without luck.
I will try it later with a clean rebuild of the environment..
matteius commentedon Oct 20, 2017
@xeor Well it is very well possible that this issue isn't the issue you are experiencing, though maybe it is. The advice in this ticket has been consistent for all users experiencing this issue thus far, which lead to an out of control enqueuing of scheduled tasks and those tasking building up and not being processed properly because of that. Could you describe more your specific problem as it doesn't appear you left a lot of details about the error(s) or the unexpected outcome you are getting?
Always happy to help. Just noting that we had this issue without the DatabaseScheduler and fixed it by only changing the timezones. In my testing I showed that the schedule file generated before and after this bug were identical so I really don't think the bug is about the scheduler but rather the type of datetimes being passed into localize() call.
xeor commentedon Oct 20, 2017
Thanks for the heads-up!
I wont be able to take a deeper loop before maybe late next week or the week after. I'll keep my self informed on the progress in this thread in the mean time.
I'm not sure if my setup is anything special, but I am using docker, amqp, rabbitmq and all the newest versions of celery python packages (not rabbitmq tho).. (sorry, I don't have the env here so I can check)..
chkdmin commentedon Nov 10, 2017
I have similar issue, some times celery-beat does not work ( it doesn't send task to broker ) Additionally, it sends too much tasks at every 59 minute
I made a test task to run every minute
On minute 59, bunch of tasks starts running and when the time hits minute 0 it runs as expected again.
I have no clue about this bug..?
This is my setting in celery 4.1.0
I am using file db for schedule
dwrpayne commentedon Nov 30, 2017
I have this issue as well on python 3.6.3, pytz 2017.3, django 1.11.7, celery 4.1.0 and django-celery-beat 1.1.0.
I wipe the database first:
And the queue continues to fill at the rate of 600/sec.
My settings are (I set everything I could find because the documentation is extremely unclear and outdated in several places):
So it's clear what is happening is that celery runs the task at 08:28:59-08, but then when storing the last_run_time, it is still adding 8 hours to the time to get 16:28:59-08 before storing it in the DB.
Taking a quick look at schedules.py tells me we are returning a timedelta or # seconds from crontab.is_due().
I don't have more time to keep digging here, but obviously something inside the crontab class is getting a timedelta between the current time and the current time with its tz
replaced(not converted).I would be very suspicious of lines that
replacetimezones.matteius commentedon Dec 13, 2017
Alright -- If everyone that had this bug could clone master and re-test that it fixes the issue for you. My PR was merged in last night and I just verified that it fixed the bug but it would be good to get additional confirmation of that for those that use the DB scheduler or other backends. Thanks!
auvipy commentedon Dec 21, 2017
9765151 apply this and check