Skip to content

Commit

Permalink
Do not fast forward rrule if count is set
Browse files Browse the repository at this point in the history
Fixes a bug where a schedule that was created
to run only once will continue to run repeatedly.

e.g. an rrule with
dtstart 20240730; count 1; freq MINUTELY

This job will run on 20240730, and should never
run again.

However, the next time the schedule
update_computed_fields runs, the dtstart
will fast forward to today's date, and
next_run will be computed from that. This will trigger
the job to run again, which is not intended.

If count is set, we just should not fast forward the
rrule and always calculate next_run based on original
dtstart.

Signed-off-by: Seth Foster <[email protected]>
  • Loading branch information
fosterseth committed Dec 10, 2024
1 parent a129bc8 commit a9ed21f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions awx/main/models/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _fast_forward_rrule(rrule, ref_dt=None):
if rrule._freq not in {dateutil.rrule.HOURLY, dateutil.rrule.MINUTELY}:
return rrule

if rrule._count:
return rrule

if ref_dt is None:
ref_dt = now()

Expand Down
6 changes: 6 additions & 0 deletions awx/main/tests/unit/utils/test_schedule_fast_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def test_future_date_does_not_fast_forward():
assert new_rrule == rrule


def test_rrule_with_count_does_not_fast_forward():
rrule = dateutil.rrule.rrule(freq=MINUTELY, interval=5, count=1, dtstart=REF_DT)

assert rrule == _fast_forward_rrule(rrule, ref_dt=REF_DT)


@pytest.mark.parametrize(
('freq', 'interval'),
[
Expand Down

0 comments on commit a9ed21f

Please sign in to comment.