Repository navigation
feat(api): extend every active Series each day with a timer function - #226
Conversation
A Series makes its Occurrences when it is created, but nothing moved the
8-week horizon forward afterwards. A daily timer function now does it.
- SeriesExtender lists the Series row keys and extends each Series from one
"now" read once per run. It makes the same call a create makes:
ReconcileAsync(series, [], kept, now) with every stored Occurrence kept
and no candidates. It reuses the Shared generator, the derived Occurrence
id and the atomic add, so it only adds what the horizon reaches. It never
rewrites, moves or deletes an Occurrence, never makes a cancelled key
again and never writes the Series row. A second run, an overlapping run
or one racing a create makes no twin and overwrites nothing.
- If one Series fails (a read or write error, a malformed row, a row key
that is not an id), the failure is logged at error level with its id
and the run moves on to the next Series. A Series deleted after the
listing is skipped. A cancellation stops the run.
- Each run logs one line: Series seen, Occurrences created, Series failed
(Information level, or Error with the failed ids when any failed). The run
does not throw on a Series failure. RouteFailures maps HTTP failures to
status codes and has no timer analogue; the next daily run retries.
- SeriesTimerFunctions.Run ("ExtendSeries") is a thin timer trigger, NCRONTAB
"0 0 4 * * *" (04:00 UTC), RunOnStartup false. It has no HTTP surface, so
the anonymous HTTP triggers and the Static Web App link are unchanged.
- New package: Microsoft.Azure.Functions.Worker.Extensions.Timer 4.3.1.
Refs #204
|
Worker notes for Nerd (#204 part 3, the daily timer). New dependency. Schedule. NCRONTAB DISPOSITION
Doc lines wanted (for the docs card; I edited no docs):
Observations (not fixed)
|
Summary
🎉 No failed tests in this run. Github Test Reporter by CTRF 💚 🔄 This comment has been updated |
… flight is not undone A cancel records the Occurrence's key in the Series' Skipped list first and deletes the Occurrence row second. The daily run read the Series row first and the Occurrences second, so a cancel that landed between the two reads was in neither the run's Skipped nor its kept list. The run's atomic add then made the cancelled Occurrence again, and nothing ever removed it. SeriesExtender now reads the Occurrences before the Series. A cancel in flight is then either already in Skipped or still in kept, so it is never made again. Tests: - An_Occurrence_cancelled_while_the_run_reads_the_Series_is_not_made_again cancels the third Occurrence through the Event API between the run's two reads; it fails on the old read order. - A_row_in_another_partition_of_the_Series_table_is_not_a_Series answers the listing through the filter it receives, so dropping the partition filter from the listing fails it. Refs #204
Review fix: new head
|
| Item | Disposition | Proof |
|---|---|---|
| A (major): a cancel in flight is undone by the run | DONE: Occurrences are now read before the Series. A cancel records the key on the Series and then deletes the row, so a cancel in flight is either in Skipped or still in kept. |
MW-GC.EventManager.API/Services/SeriesExtender.cs:72-73 (comment), :74-75 (OfSeriesAsync first), :76 (store.GetAsync second). Test MW-GC.EventManager.Api.Tests/Series/SeriesExtenderRaceTests.cs:110 An_Occurrence_cancelled_while_the_run_reads_the_Series_is_not_made_again: the cancel goes through the Event API (204) inside the BeforeEventQuery hook; it asserts Skipped holds the key (:127) and the Occurrence dates do not contain it (:128). |
| B (hard test gap): the listing's partition filter was unpinned | DONE: test only; production unchanged. | MW-GC.EventManager.Api.Tests/Series/SeriesExtenderFailureTests.cs:128 A_row_in_another_partition_of_the_Series_table_is_not_a_Series: the SeriesTable.QueryAsync mock answers the Series rows plus TableEntity("Marker","not-a-series") through the filter.Compile() it receives, as one page; it asserts Seen 1 (:142), Failed empty, Created 2. The filter it pins: SeriesExtender.cs:86. |
#204 timer.cancelled |
DONE (corrected): cancelled keys are never made again, including a cancel that lands while the run reads the Series. | test A above, plus the existing A_cancelled_Occurrence_is_not_made_again, plus live F4 on the new head |
The other lines of the earlier DISPOSITION (timer, reuse, untouched, idempotent, failures, logline, shared) stand as written.
Red run on the old head (31922ca, the test added, production unchanged)
Passed A_row_in_another_partition_of_the_Series_table_is_not_a_Series [703 ms]
Failed An_Occurrence_cancelled_while_the_run_reads_the_Series_is_not_made_again [70 ms]
Error Message:
Assertion failed. Expected collection to not contain the specified element.
unexpected: "2027-03-18T19:00:00-05:00"
collection: ["2027-03-04T19:00:00-05:00", "2027-03-11T19:00:00-05:00", "2027-03-18T19:00:00-05:00", "2027-03-25T19:00:00-05:00", "2027-04-01T19:00:00-05:00", "2027-04-08T19:00:00-05:00", "2027-04-15T19:00:00-05:00", "2027-04-22T19:00:00-05:00", "2027-04-29T19:00:00-05:00"]
Stack Trace:
at ...SeriesExtenderRaceTests.An_Occurrence_cancelled_while_the_run_reads_the_Series_is_not_made_again() in .../SeriesExtenderRaceTests.cs:line 128
Total tests: 2 Passed: 1 Failed: 1
B is meant to be green on the old head, because the filter was already there. It is a pin, and the mutation below makes it go red.
Mutations (each applied to production, then the FULL Api.Tests run, then restored; the file was verified identical afterwards)
| # | Mutation | Result | Failing test |
|---|---|---|---|
| MA | read order swapped back (store.GetAsync before OfSeriesAsync) |
KILLED: 1 red (869 passed, 1 failed, 4 skipped, 874 total) | An_Occurrence_cancelled_while_the_run_reads_the_Series_is_not_made_again |
| MB | listing filter dropped (e => true) |
KILLED: 1 red (869 passed, 1 failed, 4 skipped, 874 total) | A_row_in_another_partition_of_the_Series_table_is_not_a_Series (Assert.AreEqual(1, run.Seen)) |
Numbers (cold: clean-build.sh, build --no-incremental, test --no-build, on 75c796f)
- Build: 0 errors, 0 warnings.
- Api.Tests: 870 passed + 4 skipped (874) = 868 + 2 new. No test removed, renamed or changed, and no existing assertion touched.
- Web.Tests: 940 passed.
- E2E: 17 (5 passed + 12 skipped without the stack); 17/17 passed against the live stack below.
Live run on 75c796f (with-slot.sh, slot 0, same timer_flows.py as the first run)
PASS F0 the host lists the timer function and it did not run on startup
PASS F1 create a weekly Series | created=8 rows=8
PASS F2 two runs: the second creates nothing | run1 summary=(1, 0, 0); run2 summary=(1, 0, 0); Occurrence rows unchanged across both=True (count 8); Series row unchanged=True
PASS F3 a deleted Occurrence comes back with the same id, nothing else changes | 7 left; run summary=(1, 1, 0); back with same id=True, same fields=True; others unchanged=True; Series row unchanged=True
PASS F4 a cancelled Occurrence stays gone after a run | key in Skipped=True; run summary=(1, 0, 0); still gone=True; rows unchanged=True (count 7); Series row unchanged=True
PASS F5 a Series with a past end gets nothing | create created=0; run summary=(2, 0, 0); Occurrence rows=0; Series row unchanged=True
=== SUMMARY F0=PASS, F1=PASS, F2=PASS, F3=PASS, F4=PASS, F5=PASS
The 10 baseline API flows all passed. Repo E2E against the slot: 17 of 17 passed.
Observations
These are the four from the first comment, unchanged: ReconcileAsync's Held is always empty for the timer; OfSeriesAsync reads the whole Events table once per Series (O(Series × Events)); invoking the timer from the admin endpoint needs the master key in Azure; running E2E under with-slot.sh needs PLAYWRIGHT_BROWSERS_PATH.
Summary
Adds the daily timer function from #204 (part 3). When a Series is created it makes its Occurrences for the next 8 weeks (at least the next one), but until now nothing moved that horizon forward.
ExtendSeriesruns every day at 04:00 UTC and extends every Series with the same callPOST /api/seriesalready makes.Change
Services/SeriesExtender.cs(new).ExtendAllAsync(TimeProvider clock, CancellationToken ct)returnsSeriesExtension(Seen, Created, Failed).SeriesOccurrences.ReconcileAsync(series, [], kept, now, ct), with every stored Occurrence's key askeptand no candidates. This is exactly whatCreatedoes.OccurrenceGeneratoralready returns nothing after the end.Functions/SeriesTimerFunctions.cs(new). A thin[Function("ExtendSeries")]with[TimerTrigger("0 0 4 * * *", RunOnStartup = false)]. It only calls the extender.Program.csregistersSeriesOccurrencesandSeriesExtenderas singletons over the existing table stores.MW-GC.EventManager.API.csprojadds one new dependency:Microsoft.Azure.Functions.Worker.Extensions.Timer4.3.1. That is the current stable release on nuget.org; it depends onWorker.Core1.18.0 andExtensions.Abstractions1.3.0, both satisfied by the Worker 2.52.0 already referenced. Cold build: no NU* or version warnings.Failure policy. When one Series fails (a read error, a write error, a malformed schedule, a rule the generator refuses, a row key that is not an id):
Series extension: N Series seen, M Occurrences created, K Series failed. It is logged at Information, or at Error with the failed ids when K > 0.RouteFailuresmaps HTTP failures to status codes and has no timer counterpart, and a throw would only add a host-level failure on top of the per-Series errors. The next daily run retries.Validation
Base
origin/devmoved from41d3a04to02d09f5(#221, Web only, no file in common) during the work, so the branch was rebased (one commit, no conflict) and everything below was re-run on the rebased head.41d3a0402d09f5MW-GC.EventManager.Api.Tests/Series/. No existing test was changed or removed.Live run (worker,
with-slot.sh, Azurite + Functions host + Web + SWA). The timer was invoked throughPOST /admin/functions/ExtendSeries(202; no key needed on the local host). Rows were read and deleted straight in Azurite.origin/dev(control)ExtendSeries, no run on startup1 seen, 0 created, 0 failed; every row and the Series row byte for byte unchanged1 created, same id and fields, the other 7 rows and the Series row unchangedDELETE /api/events/{id}, invoke:0 created, it stays gone, rows and Series row unchanged0 created, no rowsNotes
Refs #204(notCloses): Nerd closes spec(0.6.0): recurring Events as a Series that generates Occurrences #204 by hand once every part has landed..github/or doc file is touched. The generator was reusable as it is.