Make QueueManager message fetching interrupt-driven#159
Open
stidsborg wants to merge 4 commits into
Open
Conversation
Drop the eager FetchAndNotify() from the Subscribe hot path. The initial store read now happens once in Initialize(); subsequent reads are driven by Interrupt()/FetchMessagesOnce(). Subscribe instead drains already-buffered messages in-memory via DeliverMessages() so a message that arrived before the wait is still delivered. Also consolidate the duplicated delay/continuation in Subscribe into a single Task.Delay, and rename ExpireSubscription to ExpireOrSuspendSubscription to reflect its dual behavior.
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
Moves
QueueManagerfrom eager per-Subscribestore pulling to an interrupt-driven model.Subscribeno longer fetches from the store. Previously everySubscribecall didawait FetchAndNotify()(a store read) on the hot path. Now the initial store read happens once inInitialize(), and subsequent reads are driven byInterrupt()→FetchMessagesOnce().Subscribedrains buffered messages in-memory. It callsDeliverMessages()after registering the subscription, so a message that was fetched before the flow started waiting (e.g. already in the store, or returned in a multi-message batch) is still delivered immediately instead of waiting out the max-wait timeout and suspending.Task.Delay(...).ContinueWith(...)across the timeout/no-timeout branches is now a singleTask.Delay, picking the sooner of the max-wait and the timeout.ExpireSubscription→ExpireOrSuspendSubscriptionto reflect its dual behavior (expire on timeout vs. suspend on max-wait).Testing
dotnet test ./Core/Cleipnir.ResilientFunctions.Tests— full in-memory suite: 514/514 passedFunctionCompletesAfterAwaitedMessageIsReceived,FunctionIsSuspendedWhenAwaitedMessageDoesNotAlreadyExist,InterruptSuspendedFlows, and the multi-message pull tests.--blame-hang-timeout 60s; no hangs.🤖 Generated with Claude Code