sibson / redbeat

RedBeat is a Celery Beat Scheduler that stores the scheduled tasks and runtime metadata in Redis.
Apache License 2.0
916 stars 130 forks source link

bug report: repeated execution of first task after establishing a new schedule(because of missing entry.last_run_at) #154

Open Mo-Xianyuan opened 4 years ago

Mo-Xianyuan commented 4 years ago

this is my case:

my codes are shown below:

··· name = "celery_task_schedule" task='application.service.celery_tasks.request_json' crontab = celery.schedules.crontab(minute="0", hour="0", day_of_month="", month_of_year="", day_of_week="*") args = ['my', 'args'] kwargs = {} entry = RedBeatSchedulerEntry(name, task, crontab, args=args, kwargs=kwargs, app=app) entry.save() ···

then something weird happened: assume that it is 2020-03-20 today, and after saving my schedule , the task will run at the below times:

2020-03-20 23:55:00 2020-03-21 00:00:00 2020-03-22 00:00:00 2020-03-23 00:00:00 2020-03-24 00:00:00

i mean, the execution in 2020-03-20 23:55:00 should not happen !

i read the code ,and find this bug comes from schedulers.py:

i think the way to solve this problem is that:

But, the author says the operation of setting last_run_at = utcnow() in celery.ScheduleEntry confusing and wrong, i am wondering if there are other cases that i have not considered, thx.

I really need help, thanks!!!!

cooperbaird commented 4 years ago

I am experiencing this same behavior. Also would really like it fixed