Django-celery-beat: Scheduled tasks don't get executed

Created on 22 Feb 2017  路  12Comments  路  Source: celery/django-celery-beat

So I have been trying to setup celery for quite a few hours and after some time I sort of managed to get it working. Now the part that I am currently stuck is that the scheduled tasks from beat aren't getting executed by celery workers. It seems that they aren't actually being sent to beat? The PeriodicTask objects are getting creating, but not executed.

Celery starts up fine by using:

celery -A proj worker --loglevel=DEBUG --concurrency=12 -B -S django -E -n worker1@pw --without-gossip --without-mingle --without-heartbeat
2017-02-21T23:00:32.730193+00:00 app[worker1.1]: [2017-02-21 23:00:32,728: INFO/MainProcess] Connected to amqp://**:**@antelope.rmq.cloudamqp.com:5672/
2017-02-21T23:00:32.740966+00:00 app[worker1.1]: [2017-02-21 23:00:32,740: INFO/Beat] beat: Starting...
2017-02-21T23:00:32.765330+00:00 app[worker1.1]: [2017-02-21 23:00:32,765: INFO/MainProcess] worker1@pw ready.



md5-8bf45181eccce644a601d1b487d275fd



    def start_collecting(self, interval=1):
        if PeriodicTask.objects.filter(task='twitch_stats.tasks.get_all_stats').count() == 0:
            schedule, created = IntervalSchedule.objects.get_or_create(
                every=interval,
                period=IntervalSchedule.MINUTES,
            )
            PeriodicTask.objects.create(
                interval=schedule,
                name='Collecting statistics',
                task='twitch_stats.tasks.get_all_stats',
                enabled=True,
            )
            print(PeriodicTask.objects.count())



md5-ab021f5db07f794bd61e31fc51b81980



2017-02-21T23:25:08.867896+00:00 app[web.1]: 1



md5-c7ea27d1b4045902e24b2ed213139942



2017-02-21T23:25:36.554762+00:00 app[worker1.1]: [2017-02-21 23:25:36,554: DEBUG/Beat] beat: Waking up in 5.00 seconds.
2017-02-21T23:25:41.557634+00:00 app[worker1.1]: [2017-02-21 23:25:41,557: DEBUG/Beat] beat: Waking up in 5.00 seconds.

Most helpful comment

I have the same problem when I edit a periodic task from the django admin interface. I need to restart everything to fix the problem

All 12 comments

Well so I did more digging today and it seems it might have been somewhat related to deleting the task rather than disabling it. Changed that to only edit already existing task and now... Even worse. It seems that the tasks don't get updated in beat scheduler after I modify their objects in Django. See picture:
capturea
Between updates the enabled flag is still false, yet the tasks get executed:

2017-02-22T11:41:12.809197+00:00 app[worker1.1]: [2017-02-22 11:41:12,808: DEBUG/Beat] beat: Waking up in 4.93 seconds.
2017-02-22T11:41:17.765244+00:00 app[worker1.1]: [2017-02-22 11:41:17,764: INFO/Beat] Scheduler: Sending due task Collecting statistics (twitch_stats.tasks.get_all_stats)
2017-02-22T11:41:17.766246+00:00 app[worker1.1]: [2017-02-22 11:41:17,766: DEBUG/Beat] twitch_stats.tasks.get_all_stats sent. id->2bdb0223-bae9-476e-ae18-9175e07586b8

By restarting the worker process I can get the tasks to update, but if I change anything to them during runtime it is not being applied or rather applied in beat worker.

So it seems this is the issue I am having... https://github.com/celery/django-celery-beat/issues/7

Installing latest django-celery-beat version from this repo didn't seem to help, but https://github.com/HealthTechDevelopers/celery@master seemed to help. Now scheduler seems to be updating fine.

2017-02-22T19:51:01.799004+00:00 app[worker1.1]: [2017-02-22 19:51:01,798: INFO/Beat] DatabaseScheduler: Schedule changed.
2017-02-22T19:51:01.799130+00:00 app[worker1.1]: [2017-02-22 19:51:01,799: INFO/Beat] Writing entries...

I have the same problem when I edit a periodic task from the django admin interface. I need to restart everything to fix the problem

same problem here :(
no fixes ?

same here

Same here.
I checked #7 feed and it seems that the problem is not completely solved.

I've also done some digging the ONLY way I've found to get it back to normal is to remove all periodic tasks and restart celery beat.

For me that looks like this.

celery -A <APPNAME> worker --events -B -S django -l debug
celery -A <APPNAME> events -l debug --camera django_celery_monitor.camera.Camera --frequency=2

same here

No idea what is going on. But when I ran two beats and a single worker which doesn't make any sense to me, one of the beat processes started to send periodic tasks.

One beat process gets stuck
Waking up in 4.99 seconds.

While the other says
Waking up in 5.00 seconds.
Then sends the task to the queue which is then picked up by the worker.

Celery installed as such
pip install git+https://github.com/celery/celery.git#egg=celery

Versions

django-celery-beat (1.0.1)
celery (4.0.2)
Django (1.10.1)

I have the same problem when I edit a periodic task from the django admin interface. I need to restart everything to fix the problem

How can I fix it?

whats the result with 1.4.0 release?

Was this page helpful?
0 / 5 - 0 ratings