Skip to content

Commit

Permalink
Fix/run tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
JedrzejMaluszczak committed May 27, 2022
1 parent ad38173 commit edf6cd4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django_cron/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
retry_after_failure_mins=None,
run_weekly_on_days=None,
run_monthly_on_days=None,
run_tolerance_seconds=0,
):
if run_at_times is None:
run_at_times = []
Expand All @@ -35,6 +36,7 @@ def __init__(
self.retry_after_failure_mins = retry_after_failure_mins
self.run_weekly_on_days = run_weekly_on_days
self.run_monthly_on_days = run_monthly_on_days
self.run_tolerance_seconds = run_tolerance_seconds


class CronJobBase(object):
Expand Down Expand Up @@ -122,7 +124,7 @@ def should_run_now(self, force=False):
if (
last_job
and not last_job.is_success
and get_current_time()
and get_current_time() + timedelta(seconds=cron_job.schedule.run_tolerance_seconds)
<= last_job.start_time
+ timedelta(minutes=cron_job.schedule.retry_after_failure_mins)
):
Expand All @@ -138,7 +140,7 @@ def should_run_now(self, force=False):

if self.previously_ran_successful_cron:
if (
get_current_time()
get_current_time() + timedelta(seconds=cron_job.schedule.run_tolerance_seconds)
> self.previously_ran_successful_cron.start_time
+ timedelta(minutes=cron_job.schedule.run_every_mins)
):
Expand Down

0 comments on commit edf6cd4

Please sign in to comment.