question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

interval cron issue with microseconds

See original GitHub issue

I’m trying to setup a simple job with an interval of 5 minutes:

scheduler.add_job(
    func=ping_db,
    id='ping_db',
    trigger="interval",
    minutes=5,
    misfire_grace_time=None,
    replace_existing=True
)

note: happens with trigger='cron' too which is setup at 1am to run a process.

Expected Behavior

Since the function just ping a db with a sql statement select1. Its execution is really fast. I’m expecting to get in my logs:

INFO 2019-12-24 10:29:01,743 {file name: base.py Line: 144 -- run_job()} Job "ping_db (trigger: interval[0:05:00], next run at: 2019-12-24 18:34:00 UTC)" executed successfully
DEBUG 2019-12-24 10:29:01,767 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 299.406608 seconds)

Current Behavior

What I’m getting is multiple next run times and the only difference is the microseconds:

DEBUG 2019-12-24 10:29:01,767 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 299.406608 seconds)
DEBUG 2019-12-24 10:29:01,846 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 299.400619 seconds)
DEBUG 2019-12-24 10:29:01,928 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 299.390624 seconds)
DEBUG 2019-12-24 10:29:02,017 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 299.389619 seconds)
DEBUG 2019-12-24 10:29:02,354 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 298.807571 seconds)
DEBUG 2019-12-24 10:29:02,434 {file name: base.py Line: 1020 -- _process_jobs()} Next wakeup is due at 2019-12-24 18:34:00+00:00 (in 298.801572 seconds)

Application in Flask

Context (Environment)

Python 3.7.0 Windows 10 Microsoft Windows Server 1607 Internet Information Services 10.0.14393.0

I’m using just 1 worker in IIS, and configuring the scheduler in the app with:

    # app scheduler config
    app.config['SCHEDULER_JOBSTORES'] = {
        'default': SQLAlchemyJobStore(engine=engine)
    }
    app.config['SCHEDULER_EXECUTORS'] = {
        'default': {'type': 'threadpool', 'max_workers': 20}, # ThreadPoolExecutor(20),
        # 'processpool': ProcessPoolExecutor(5)
    }
    app.config['SCHEDULER_JOB_DEFAULTS'] = {
        'misfire_grace_time': None,
        'coalesce': True,
        'max_instances': 1,
        'replace_existing': True,
    }

tried 'coalesce': True and 'coalesce': False.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, May 23, 2020

You can either follow the recommended procedure for starting the scheduler in a separate process, or wait for APScheduler v4.0 which supports job store sharing.

0reactions
virtualdvidcommented, May 23, 2020

Hi @Laurel-rao sorry for my late replay. I tried what you mentioned a while ago and the behavior was the same. The application is now on production and the issue is less. It happens sometimes randomly. Fortunately this doesn’t affect the overall of the app.

@agronholm Great news, looking forward to see what’s coming in APScheduler v4.0!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How precise is cron? - Server Fault
I am trying to set up a python script to query a DB for all updates over the past 5 minutes. Given the...
Read more >
How do I run cron per 40 millisecond in PHP - Stack Overflow
I would like to run a cron every 40 milliseconds , I have tried following script for execute a cron file every 40...
Read more >
Run unix command precisely at very short intervals WITHOUT ...
Accuracy is in the milliseconds, provided that the 'payload' date "+%N nanoseconds late" does not take longer than just under a second. You...
Read more >
Create and configure cron jobs - Google Cloud
You can use Cloud Scheduler to set up scheduled units of work, known as cron jobs, that are sent to targets on some...
Read more >
Task Scheduling | NestJS - A progressive Node.js framework
For Node.js apps, there are several packages that emulate cron-like ... Pass the interval value, as a number in milliseconds, to the decorator...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found