Skip to content
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

added delay_seconds parameter to run_pending #483

Open
wants to merge 1 commit 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
13 changes: 10 additions & 3 deletions schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Scheduler(object):
def __init__(self) -> None:
self.jobs: List[Job] = []

def run_pending(self) -> None:
def run_pending(self, delay_seconds: int = 0) -> None:
"""
Run all jobs that are scheduled to run.

Expand All @@ -94,10 +94,17 @@ def run_pending(self) -> None:
that should run every minute and you only call run_pending()
in one hour increments then your job won't be run 60 times in
between but only once.

A delay of `delay` seconds is added between each job. This helps
distribute system load generated by the jobs more evenly
over time.

:param delay_seconds: A delay added between every executed job
"""
runnable_jobs = (job for job in self.jobs if job.should_run)
for job in sorted(runnable_jobs):
self._run_job(job)
time.sleep(delay_seconds)

def run_all(self, delay_seconds: int = 0) -> None:
"""
Expand Down Expand Up @@ -773,11 +780,11 @@ def every(interval: int = 1) -> Job:
return default_scheduler.every(interval)


def run_pending() -> None:
def run_pending(delay_seconds: int = 0) -> None:
"""Calls :meth:`run_pending <Scheduler.run_pending>` on the
:data:`default scheduler instance <default_scheduler>`.
"""
default_scheduler.run_pending()
default_scheduler.run_pending(delay_seconds=delay_seconds)


def run_all(delay_seconds: int = 0) -> None:
Expand Down