Skip to content

note important information about intervals #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ This is how you do it
either do not set a `result_ttl` value or you set a value larger than the interval.
Otherwise, the entry with the job details will expire and the job will not get re-scheduled.

**IMPORTANT NOTE**: Read more about intervals in the section `Scheduler polling interval vs job interval`_ below.

------------------------
Cron Jobs
------------------------
Expand Down Expand Up @@ -238,6 +240,53 @@ The script accepts these arguments:
The arguments pull default values from environment variables with the
same names but with a prefix of ``RQ_REDIS_``.

**IMPORTANT NOTE**: Read more about intervals in the section `Scheduler polling interval vs job interval`_ below.

------------------------------------------
Scheduler polling interval vs job interval
------------------------------------------

There are two different intervals to consider when running the scheduler:

* the scheduler *polling* interval
* the job interval

This code illustrates the difference:

.. code-block:: python

from rq_scheduler import Scheduler

POLLING_INTERVAL = int(...)
JOB_INTERVAL = int(...)

# this interval defaults to 60 seconds
scheduler = Scheduler(interval=POLLING_INTERVAL)

scheduler.schedule(
scheduled_time=datetime.now(),
func=my_func,
interval=JOB_INTERVAL,
)

scheduler.run()


The intervals have to satisfy the following conditions:

* the job interval has to be greater than the scheduler interval, otherwise the job will run only as often as the scheduler polls
* the job interval has to be a multiple of the scheduler interval, otherwise the job will run at irregular intervals

For example, if the scheduler polls every 3 seconds and the job interval is 10 seconds, the job will run every 12 seconds:

* 0s: scheduler polls
* 3s: scheduler polls
* 6s: scheduler polls
* 9s: scheduler polls
* 10s: job is supposed to run
* 12s: scheduler polls, and job only now runs


Running the Scheduler as a Service on Ubuntu
--------------------------------------------

Expand Down