Repository navigation
Adds an optional whole-delivery wrapper - #152
Merged
Merged
Conversation
Config takes :around_delivery, handed (scope, door, work), which must call work exactly once and answer what it answered. route/3 runs its bindings read, key_refused rows and deliveries inside one call (door :route, so the webhook front and each Broadway message too), the Broadway partitioner its bindings read (:partition), and the BasicHTTP front its delivery after the token resolves (:basichttp). The execution-target door is not wrapped. Left out, the router issues the same statements and answers as before, pinned against statements captured at bbe6c16. ADR-0003 gains an Amendment at proposed recording the doors, the execution target per shape, and what a context reaches. Refs: sr-t36w
A wrapper that raised, exited or threw after its work returned left the work's report in the caller's mailbox: in Broadway's producer at the :partition door, or in a host's long-lived process at :route. The wrapper is now called inside try/catch, the reports are drained on every way out, and a failure is re-raised with its own kind, reason and stacktrace. Reports stay messages rather than a counter in the process dictionary, since a wrapper may run the work elsewhere. Refs: sr-t36w
johnnyt
force-pushed
the
sr-t36w-whole-delivery-wrapper
branch
from
October 2, 2026 10:21
2ba1e68 to
cb8ff2b
Compare
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.
Adds
:around_delivery, one optional configuration option that runs a whole delivery inside a host's own context, and records it as an Amendment on ADR-0003 at proposed (in this PR, appended at the foot; zero removed lines underdocs/adr/).What changes
StatifierRouter.Configtakes:around_delivery: a module exportingaround_delivery/3or an arity-3 fun, handed(scope, door, work). It must callworkexactly once and answer whatworkanswered; anything else raisesArgumentError(Config.around_delivery/4, package-internal).new/1checks the shape as it checks the hooks.:route(StatifierRouter.route/3: the bindings read, everykey_refusedrow and every delivery, so alsoStatifierRouter.Webhook.handle/3and each Broadway message),:partition(StatifierRouter.Broadway.partition/3's bindings read, in the producer),:basichttp(StatifierRouter.BasicHTTP.Front's delivery, after the token resolves, which stays outside).SendHandlercallingDelivery.deliver_event/4). At the executor seam it runs inside the sender's wrapped step; on the send-processor shape, and from a step the router did not drive, nothing of the router's encloses it. The record says so per shape.### Wrapping a whole deliverysubsection. Moduledocs ofConfig,Delivery,Broadway,BasicHTTP.Frontandroute/3describe the door each owns.try/catch, so the work's report is drained from the caller's mailbox on every way out of the wrapper, and a failing wrapper is re-raised with its own kind, reason and stacktrace. Reports stay messages rather than a process-dictionary counter, because a wrapper may run the work in another process.Provenance
:around_deliveryand the door atoms:route,:partition,:basichttp; holding the wrapper to its contract withArgumentError(a wrapper that returns aRepo.transaction/2answer would otherwise pass{:ok, answer}off as a routing answer); wrapping the front at its own delivery call rather than insidedeliver_event/4, becauseSendHandlercalls that function too.lib/statifier_router/delivery.exgains only a moduledoc paragraph saying the wrapper is called by its callers.Tests
test/statifier_router/around_delivery_test.exs, not async (Broadway's processes need the shared sandbox, asBroadwayTestdoes, and a telemetry handler on the test repo's query event captures every statement with the process-dictionary context it ran under):bbe6c16, before the option existed (normalized for savepoint numbers, parameter numbers and Ecto's column order), for a create, a BasicHTTP POST, a finishing step, a duplicate and akey_refusedrow;route/3: one:routecall, the bindings resolver and every statement, both ledger inserts included, under the context;Webhook.handle/3throughroute/3;:partitioncall in the producer whose resolver call sees the context, a:routecall in the processor whose statements carry it;Each test carries a
# sabotage:note from a mutation actually run; every mutation applied, failed its test on an assertion, and was restored byte-equal before the next.Gate
Full
mix qualitygreen locally on the rebased head (448 of 448 tests, 98.0% coverage, isolated tests, Dialyzer, Docs, Doc links, Credo).Review tier
Contract: a new public configuration option on the doors it wraps. Opened for the conductor's cold review; not merged by its author.