Allowing finer control on claiming logic #19
Merged
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.
This patch adds a
ShouldClaimPendingMessagecallback to the subscriber's config, to allow users to decide whether a message that's been pending for more thanMaxIdleTimeshould actually be claimed or not.My use case for this is that I have a type of async tasks for which the time needed to process one task can vary wildly, anywhere from 1 second to several minutes, and it's impossible to know ahead of time how long it will take. So to avoid long-running instances to be considered dead and be endlessly claimed back & forth, I would have to have a
MaxIdleTimeof several minutes.However, that would also meant that it would take that long to detect dead workers, which is also not acceptable for my use case.
This new config option solves this problem by allowing me to have a short
MaxIdleTime, but then leverage an external heartbeat mechanism in myShouldClaimPendingMessagecallback to decide if a worker is actually dead, or just busy with a long-running instance of the task.Added tests on the claim behaviour.