Skip to content

Commit

Permalink
Fix logic bug in create_schedule() re. backfills (#693)
Browse files Browse the repository at this point in the history
Don't ask for immediate trigger when a backfill is requested, and don't
ask for a backfill when an immediate trigger is requested.

Closes #678.
  • Loading branch information
josh-berry authored Nov 22, 2024
1 parent 97a2b7a commit 853889c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions temporalio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5502,8 +5502,12 @@ async def create_schedule(self, input: CreateScheduleInput) -> ScheduleHandle:
overlap_policy=temporalio.api.enums.v1.ScheduleOverlapPolicy.ValueType(
input.schedule.policy.overlap
),
),
backfill_request=[b._to_proto() for b in input.backfill],
)
if input.trigger_immediately
else None,
backfill_request=[b._to_proto() for b in input.backfill]
if input.backfill
else None,
)
try:
request = temporalio.api.workflowservice.v1.CreateScheduleRequest(
Expand Down
16 changes: 10 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,33 +1104,37 @@ async def test_schedule_backfill(
state=ScheduleState(paused=True),
),
backfill=[
# 2 actions on Server >= 1.24, 1 action on Server < 1.24. Older
# servers backfill workflows in the interval [start_at, end_at), but
# newer servers backfill the interval [start_at, end_at].
ScheduleBackfill(
start_at=begin - timedelta(minutes=30),
end_at=begin - timedelta(minutes=29),
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
)
],
)
# The number of items backfilled on a schedule boundary changed in 1.24, so
# we check for either
assert (await handle.describe()).info.num_actions in [2, 3]
# We accept both 1.24 and pre-1.24 action counts
assert (await handle.describe()).info.num_actions in [1, 2]

# Add two more backfills and and -2m will be deduped
await handle.backfill(
# 3 actions on Server >= 1.24, 2 actions on Server < 1.24
ScheduleBackfill(
start_at=begin - timedelta(minutes=4),
end_at=begin - timedelta(minutes=2),
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
),
# 3 actions on Server >= 1.24, 2 actions on Server < 1.24, except on
# Server >= 1.24, there is overlap with the prior backfill, so this is
# only net +2 actions, regardless of Server version.
ScheduleBackfill(
start_at=begin - timedelta(minutes=2),
end_at=begin,
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
),
)
# The number of items backfilled on a schedule boundary changed in 1.24, so
# we check for either
assert (await handle.describe()).info.num_actions in [6, 8]
assert (await handle.describe()).info.num_actions in [5, 7]

await handle.delete()
await assert_no_schedules(client)
Expand Down

0 comments on commit 853889c

Please sign in to comment.