Repository navigation
feat: deferred delivery with handler defaults and publish-time override - #94
Merged
Merged
Conversation
Add `defer` to handler config (static `{ delayMs } | { until }` or a function
of the event) and a `defer` publish option that overrides it for every handler
of that event. The processor resolves the deferral at fan-out into
`run_after` on each new delivery; `delayMs` counts from `event.created_at` so
fan-out retries are deterministic.
- `TxOBEvent.defer` persisted; new `defer JSONB` column on `txob_events`
- `TxOBNewDelivery.run_after: Date | null` (breaking for custom stores)
- all stores honor `run_after` on fan-out; redis routes to the delayed zset
- processor schedules a poll at the earliest due time; `scheduleTick` skips
timers longer than `pollingIntervalMs` (also avoids setTimeout overflow)
- pg fan-out passes `run_after` as `text[]`: postgres.js under Drizzle cannot
encode `timestamptz[]` parameters
- docs, example, migration notes, changeset
Resolve the publish `defer` option at publish time into `event.defer_until` instead of persisting the config object. The column is a plain TIMESTAMPTZ, validation happens once in `publish`, and stores carry a Date like `created_at` rather than a JSON blob. Handler defers still resolve at fan-out.
mongod 8.0.21-8.0.36 and 8.3.0-8.3.15 exit at startup on the GitHub runners' Ubuntu kernels: their kernel 6.19+ guard does not recognise Ubuntu's version numbering as already carrying the rseq fix (SERVER-131779). The exemption ships in 8.3.16 / 8.0.37, which Docker Hub has not published yet; 9.0.4 has it. Also drops the ubuntu-24.04 pin: that image's kernel is affected too.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #94 +/- ##
==========================================
+ Coverage 95.88% 96.04% +0.16%
==========================================
Files 32 33 +1
Lines 2163 2253 +90
Branches 416 455 +39
==========================================
+ Hits 2074 2164 +90
Misses 72 72
Partials 17 17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
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.
Summary
Adds deferred delivery: a handler declares a default
deferand a publisher can override it per event. The publish-time defer is resolved to a timestamp at publish and stored on the event asdefer_until; a handler's defer is resolved at fan-out. Either way the result lands inrun_afteron each new delivery.TxOBDefer = { delayMs: number } | { until: Date }.delayMscounts fromevent.created_at, so fan-out retries resolve to the same time.event.defer_until: Date | nullis persisted and visible to handlerdeferfunctions and handlers.publish(publish-time), or leaves the event unfanned with a logged error (handler function), same path as invalid priority.scheduleTicknow ignores timers longer thanpollingIntervalMs, which also keeps clear of thesetTimeout24.8 day overflow previously reachable viabackoffUntil.Stores
defer_until TIMESTAMPTZontxob_events;completeFanoutinsertsrun_afterdefer_untilon event record;run_afteron new deliveriesdefer_untilhash field (ms); fan-out script places future deliveries in the delayed zsetPostgres fan-out passes
run_afterastext[]and casts in SQL: postgres.js (under Drizzle) has no encoder fortimestamptz[]parameters.Breaking
ALTER TABLE txob_events ADD COLUMN IF NOT EXISTS defer_until TIMESTAMPTZ;(see MIGRATING.md).TxOBNewDelivery.run_after: Date | nullis required;insertEventmust persistevent.defer_untiland return it from claims.Tests
src/defer.test.ts: normalize / resolve units.test/units.test.ts: compile validation, precedence (publish > handler fn > static), invalid defer leaves event unfanned, due-time poll ahead of a 60 s interval.test/contract.ts: store-level futurerun_afterheld until due; processor-level defer with publish override. Runs against all five stores and seven ORM adapters.All backends green. Postgres plus ORM adapters pass in isolation (304 tests). In one fully parallel 20 minute run, two kysely tests timed out from load, one of them pre-existing; neither reproduces alone.