next run time missed by some seconds in job scheduling in apscheuler

user3545251 picture user3545251 · May 14, 2015 · Viewed 7k times · Source

i have a function to execute cron job as

def add_config_job(sched, job):

    module = JOB_METHODS.get(job["type"])
    if module is None:
        logging.warn("job type %r not supported", job["type"])
        return

    func = module.cron_job
    args = (job,)
    name = "%s__%s" % (job["name"], job["id"])
    start_date = job.get("start_date")
    run_at = job["run_at"]

    if isinstance(job["run_at"], dict):
        sched.add_cron_job(func, args=args, name=name, start_date=start_date,
                           **run_at)
    elif isinstance(job["run_at"], basestring):
        sched.add_date_job(func, args=args, name=name, date=run_at)
    else:
        logging.warn("unsupported 'run_at' type (%s given)", run_at)

and I get the error as missed job by some seconds as

2015-05-14_00:00:02.76629 WARNING: Run time of job "Daily VPN Connexion__1 (trigger: cron[day='*', hour='0', minute='0', second='0'], next run at: 2015-05-14 00:00:00)" was missed by 0:00:02.493426
2015-05-14_00:00:02.79309 WARNING: Run time of job "Daily Report VPN Connection ALIGRO__1 (trigger: cron[day='*', hour='0', minute='0', second='0'], next run at: 2015-05-14 00:00:00)" was missed by 0:00:02.777450

what is the cause of this misfiring of the job? how can we avoid it? in some pages I found to increase the misfire_grace_time from the default of 1 second. shouldn't be the scheduler schedule in proper time without missing it?

Answer

Alex Grönholm picture Alex Grönholm · May 15, 2015

It seems to be that your process is too busy to start the jobs in a timely manner. The misfire_grace_time option is there to prevent jobs from firing after they're no longer relevant. If something needs to happen at some exact time and it's delayed too much, it shouldn't happen at all. Increasing misfire_grace_time is the solution if this is happening and you don't care about accuracy so much.