sibson / redbeat

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

crontab task not run right #153

Open chen-zhuohan opened 4 years ago

chen-zhuohan commented 4 years ago

there are twice problems, both related to crontab task

  1. Tasks that should have been run hourly will always run a few minutes before the hour.
  2. Tasks that should have been run hourly just run few times after server start. this is my simple code, I user celery==4.3.0 and celery-redbeat==0.13.0

    def add_missionary(mission_id: int, run_time: str, task: str = 'mission.run_mission'):
    name = RUNNING_TASK_NAME.format(mission_id)
    args = (mission_id,)
    interval = crontab(minute='1')
    
    entry = RedBeatSchedulerEntry(name, task, interval, args=args, app=celery)
    entry.save()

    in addition, I has two task, one is run every mintue ( interval(60) ), the another one just as the over code. The task is the same one, but args and run time are different. the run time: 2020-03-10 11:56 (should not run at this time) 2020-03-10 12:01 2020-03-10 13:01

2020-03-11 17:01 2020-03-11 17:56 (should not run at this time) (no more run)

redis info after no more run:

127.0.0.1:6379> zrange redbeat::schedule 0 -1
1) "redbeat:mission-2"
2) "redbeat:mission-1"
3) "redbeat:celery.backend_cleanup"
127.0.0.1:6379> hgetall redbeat:mission-1
1) "meta"
2) "{\"last_run_at\": {\"__type__\": \"datetime\", \"year\": 2020, \"month\": 3, \"day\": 12, \"hour\": 10, \"minute\": 19, \"second\": 22, \"microsecond\": 825117}, \"total_run_count\": 995}"
3) "definition"
4) "{\"name\": \"mission-1\", \"task\": \"mission.run_mission\", \"args\": [1], \"kwargs\": {}, \"options\": {}, \"schedule\": {\"__type__\": \"interval\", \"every\": 60.0, \"relative\": false}, \"enabled\": true}"
127.0.0.1:6379> hgetall redbeat:mission-2
1) "meta"
2) "{\"last_run_at\": {\"__type__\": \"datetime\", \"year\": 2020, \"month\": 3, \"day\": 11, \"hour\": 17, \"minute\": 56, \"second\": 13, \"microsecond\": 68178}, \"total_run_count\": 1}"
3) "definition"
4) "{\"name\": \"mission-2\", \"task\": \"mission.run_mission\", \"args\": [2], \"kwargs\": {}, \"options\": {}, \"schedule\": {\"__type__\": \"crontab\", \"minute\": \"1\", \"hour\": \"*\", \"day_of_week\": \"*\", \"day_of_month\": \"*\", \"month_of_year\": \"*\"}, \"enabled\": true}
jpaulynice commented 4 years ago

I opened a PR and an issue here: https://github.com/sibson/redbeat/issues/160, I think that's the problem, but looking for feedback...