fix: publish schedules after creation watermark

This commit is contained in:
lda
2026-09-09 18:39:00 +07:00 Verified
parent 86a52adda5
commit 39993c9d5e
2 changed files with 33 additions and 4 deletions
+13 -4
View File
@@ -21,7 +21,7 @@ from wf_scheduling.history import FileScheduleHistoryRecorder, HistoryEntry
from wf_scheduling.models import OccurrenceRecord, Schedule
from wf_scheduling.occurrences import occurrence_id
from wf_scheduling.prepare import PreparationRejected, SchedulePreparer
from wf_scheduling.store import StaleScheduleRevisionError
from wf_scheduling.store import ScheduleExistsError, StaleScheduleRevisionError
from .models import (
JsonProjector,
@@ -207,11 +207,20 @@ class WorkflowScheduleApi:
}
)
self._validate_definition(schedule)
stored = store.create_schedule(schedule)
# Creation never backfills time before the revision: the consumed
# watermark starts at creation so catch-up only ever covers
# downtime after this revision, never pre-creation instants.
# watermark starts at creation so catch-up only ever covers downtime
# after this revision, never pre-creation instants. Check the id
# before this write so a duplicate create cannot overwrite the
# existing schedule's watermark; publishing the schedule last keeps
# a failed watermark write invisible to the poller.
try:
store.get_schedule(schedule_id)
except KeyError:
pass
else:
raise ScheduleExistsError(f"schedule id already exists: {schedule_id!r}")
store.save_consumed(schedule_id, now)
stored = store.create_schedule(schedule)
return _PROJECT_SCHEDULE(stored.model_dump(mode="json"))
async def get_schedule(self, *, schedule_id: str) -> ScheduleResult: