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:
in tick() function of class RedBeatScheduler, we first get self.schedule. since is 2020-03-20 23:55:00 now, and the acurate exec time 2020-03-21 00:00:00 is exactly 5 min(max_interval_time) later, so this entry is added in self.schedule.
If we dip into the definition of self.schedule, then we will find that the entry.last_run_at is None.
That's because meta is not save in redis after we call entry.save(), and the "from_key" function will initialize last_run_at as None.
then in tick(), we will call self.maybe_due(), and this function will call entry.is_due(), then call self.schedule.is_due(self.last_run_at or datetime(MINYEAR, 1, 1, tzinfo=self.schedule.tz)). And problem comes, since entry.last_run_at is None, datetime(MINYEAR, 1, 1) is passed to self.schedule.is_due, and in celery, it finds the now time is much later then the next run time after datetime(MINYEAR, 1, 1), so self.schedule.is_due return True,
finally, the worker execute in 2020-03-20 23:55:00
i think the way to solve this problem is that:
in class_method from_key, the line entry.last_run_at = meta['last_run_at'] should be deleted, and celery.ScheduleEntry sets last_run_at = utcnow() initially.
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.
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!!!!