Repository navigation
Lets a timer delivery answer a snooze - #139
Merged
Merged
Conversation
StatifierOban.Timer.Delivery.deliver/2 may now answer
{:snooze, seconds} with a positive integer (ADR-0010, proposed). The
timer worker hands it to Oban unchanged, so the job is rescheduled
without spending a retry and stays a pending, cancellable timer. Zero,
a negative count, a non-integer and an Oban period tuple match no
clause and raise, as any unrecognised answer did before. No telemetry
event is added and no bound is kept here.
The behaviour gains t:snooze/0; its moduledoc, the worker's outcome
list and the README's durable-delivery section teach the snooze for a
parked execution and keep the raise for environment failures. Tests
drive a snoozing stand-in store on the locked Oban 2.23.1: two snoozes
leave max_attempts minus attempt unchanged, the run after the unpark
delivers, a cancel reaches the snoozed row, a finished execution still
discards, and the four refused shapes raise.
Refs: sob-46l
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The code half of ADR-0010 ("A timer delivery may answer a snooze, so a parked timer spends no retries"), which is on
mainat proposed and is not edited here; it stays proposed until this code ships in a published version.What changes.
c:StatifierOban.Timer.Delivery.deliver/2may answer{:snooze, seconds}withsecondsa positive integer (decision 1), typed as the newt:StatifierOban.Timer.Delivery.snooze/0besidet:discard_reason/0.StatifierOban.Timer.Worker.perform/1returns that tuple to Oban unchanged (decision 2), so the job is rescheduled at leastsecondslater without spending a retry. The worker's own guard (is_integer(seconds) and seconds > 0) is what keeps zero, a negative count, a non-integer and an Oban period tuple out: each matches no clause and raises, as any unrecognised answer did before (decision 6); Oban 2.23.1 itself would accept zero and period tuples, and would record a negative count as a success. No telemetry event is added (decision 5) and no bound is kept (decision 7). The existing:deliveredand{:discarded, reason}answers, and the defaultStatifierOban.Timer.Delivery.Session, are unchanged: the change is additive.Docs. The
StatifierOban.Timer.Deliverymoduledoc section "A parked execution retries; it is never discarded" now teaches the snooze and keeps the raise, with its bound, for a delivery that raises; the sentence saying an Oban snooze is not available from inside the callback is gone. The callback doc names the snooze answer. The worker moduledoc's outcome list gains the snooze. The README's "Delivering timers to a durable execution" section: the durable module's{:error, {:needs_migration, _execution}}arm answers{:snooze, 300}, and the paragraph after it says what a snooze does (no retry spent, still pending, still cancellable, the period as the host's trade, no cap here) and keeps the raise as the alternative with its bound. Nothing outside that section of the README changes.Tests (
test/statifier_oban/timer/parked_execution_test.exs, Lite engine, the locked Oban 2.23.1):snoozed: 1, the row isscheduledat least 59 seconds out with no error recorded,max_attempts - attemptis the same as before the first run, and the timer is still pending for its scope; after the unpark the next run delivers and the job completes;failure: 1,snoozed: 0), leave the rowretryableon attempt 1 withmax_attemptsunchanged, and record aCaseClauseError.The stand-in store (
test/support/parked_store_delivery.ex) gainsanswer_parked_with/1; its default is still the raise, so the two existing tests in that file are untouched.Sabotage (each on
lib/statifier_oban/timer/worker.exfrom a copy, restored byte-equal and recompiled before the next): removing the snooze clause took the snooze test and the cancel test red on the drain assertion (failure: 1instead ofsnoozed: 1); droppingseconds > 0took the zero and negative cases red (a snooze and a success); droppingis_integer(seconds)took the non-integer and period-tuple cases red (a success and a snooze); answering{:snooze, 60}in place of the discard took the finished-execution test red (snoozed: 1instead ofcancelled: 1). One line above each test records it.Changelog.
changelog.d/sob-46l.mdunder Added, for the next minor, aschangelog.d/README.mdasks for a public API addition.Provenance. Two edits the file map did not name, forced by the README change: the header comment and the delivery module's comment in
test/statifier_oban/timer/parked_persisted_execution_test.exssaid that test's module is the README's durable module and that it raises; they now say it keeps the raise where the README snoozes. No test in that file changes.Gate. Full
mix qualitygreen on the rebased head (313 tests, 0 failures; format, compile with warnings as errors, credo, docs, doc links, dependencies and dialyzer all passing).Refs: sob-46l