Repetitive job was run twice in Flask project after a while

2,167 views
Skip to first unread message

Xun Zhong

unread,
Jan 21, 2015, 2:44:50 AM1/21/15
to apsch...@googlegroups.com
Hello,
  I was fairly new in using APScheduler and was developing a Flask web project. After searching a lot of web pages, I believe I cannot solve this problem on my own, please help.
  I was building a module which do a job in random interval, the job is bound with a unique id. So I used BackgroundScheduler to make an initial job, and after the job had done what I want, I created another job with the same id at the end, (I've added replace_existing=True, max_instances=1 in job's constructor, with default options 'coalesce': True, 'misfire_grace_time ': 0).
  After the project was up and running, It fine at first, but after a while, (one or two reboots maybe), it began to run the job twice at the same time, like two identical jobs were running in parallel, the log excerpt reads:

DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Next wakeup is due at 2015-01-21 07:09:46.231960+00:00 (in 2.149310 seconds)
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Looking for jobs to run
INFO:apscheduler.executors.default:Running job "delayed_praise-2380 (trigger: date[2015-01-21 07:09:46 UTC], next run at: 2015-01-21 07:09:46 UTC)" (scheduled at 2015-01-21 07:09:46.231962+00:00)
INFO:apscheduler.executors.default:Running job "delayed_praise-2380 (trigger: date[2015-01-21 07:09:46 UTC], next run at: 2015-01-21 07:09:46 UTC)" (scheduled at 2015-01-21 07:09:46.231962+00:00)
INFO:apscheduler.scheduler:Removed job delayed_praise-2380
DEBUG:apscheduler.scheduler:Next wakeup is due at 2015-01-21 07:09:47.029580+00:00 (in 0.787876 seconds)
INFO:apscheduler.scheduler:Removed job delayed_praise-2380


 I've uploaded the full log file, it was done on my own laptop and the invertal time was reduced to 3 seconds to reproduce the same symptom in a short time.
I really need the job to be done only once... Someone may have the answer? Thanks.
apscheduler-flaskProject-log.zip

Xun Zhong

unread,
Jan 21, 2015, 3:09:23 AM1/21/15
to apsch...@googlegroups.com
I forgot to mention that I need to run certain jobs limited times, so I added a counter in args, and every time I set a job, I add one to the counter, when the counter reached the limit, I will no longer add more jobs at the end of the last job.
I cannot think of a way to do this using 'interval' trigger, so I used this awkward method. Let me know if you have better ideas. Thanks.

在 2015年1月21日星期三 UTC+8下午3:44:50,Xun Zhong写道:
Message has been deleted

Xun Zhong

unread,
Jan 21, 2015, 9:20:52 AM1/21/15
to apsch...@googlegroups.com


在 2015年1月21日星期三 UTC+8下午3:44:50,Xun Zhong写道:
Hello,
Reply all
Reply to author
Forward
0 new messages