celery / django-celery-beat

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

Scheduled tasks don't get executed #27

Closed Hoffs closed 5 years ago

Hoffs commented 7 years ago

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.

Task get created fine

    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())
2017-02-21T23:25:08.867896+00:00 app[web.1]: 1

But the beat doesn't recognize

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.
Hoffs commented 7 years ago

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

Hoffs commented 7 years ago

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...
oca159 commented 7 years ago

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

niyazielvan commented 7 years ago

same problem here :( no fixes ?

faxioman commented 7 years ago

same here

frnhr commented 7 years ago

Indeed this looks like https://github.com/celery/django-celery-beat/issues/7

Revocsid commented 7 years ago

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

rh0dium commented 7 years ago

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
capooti commented 7 years ago

same here

Tanbouz commented 7 years ago

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)
Allan-Nava commented 5 years ago

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?

auvipy commented 5 years ago

whats the result with 1.4.0 release?