Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APScheduler missing jobs after adding misfire_grace_time

I am running a BlockingScheduler process that it's suppose to run several cron jobs, but it fails to run every single time with the message:

Run time of job "validation (trigger: cron[hour='3'], next run at: 2016-12-30 03:00:00 CST)" was missed by 0:00:02.549821

I have the following setup:

sched = BlockingScheduler(misfire_grace_time=3600, coalesce=True)
sched.add_jobstore('mongodb', collection='my_jobs')

@sched.scheduled_job('cron', hour=3, id='validation')
def validation():
    rep = Myclass()
    rep.run()

if __name__ == '__main__':
    sched.start()

I thought adding misfire_grace_time would do the trick, but every job is still missing to run.

like image 363
PepperoniPizza Avatar asked Jan 02 '17 13:01

PepperoniPizza


People also ask

How does APScheduler work?

In-process task scheduler with Cron-like capabilities Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please.

What is Max_instances in APScheduler?

The max_instances only tells you how many concurrent jobs you can have. APScheduler has three types of triggers: date interval cron. interval and cron repeat forever, date is a one-shot on a given date.

How do I stop APScheduler?

It only stops when you type Ctrl-C from your keyboard or send SIGINT to the process. This scheduler is intended to be used when APScheduler is the only task running in the process. It blocks all other code from running unless the others are running in separated threads.


2 Answers

try adding misfire_grace_time in @sched.scheduled_job('cron', hour=3, id='validation', misfire_grace_time=3600)

like image 79
rohan_tare Avatar answered Oct 19 '22 01:10

rohan_tare


self.scheduler = BlockingScheduler(
    logger=log,
    job_defaults={'misfire_grace_time': 15*60},
)

adding the misfire_grace_time as job_defaults will work

like image 9
deepak mahapatra Avatar answered Oct 18 '22 23:10

deepak mahapatra