feat(webhooks): implement adaptive polling in WebhookProcessorService#157
Open
Vswaroop04 wants to merge 2 commits into
Open
feat(webhooks): implement adaptive polling in WebhookProcessorService#157Vswaroop04 wants to merge 2 commits into
Vswaroop04 wants to merge 2 commits into
Conversation
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Replaces the fixed 10s setInterval with a setTimeout loop that reschedules itself based on whether the previous cycle found any pending retries: - BASE_RETRY_CHECK_INTERVAL_MS (10s) when the queue is empty — avoids unnecessary database load during quiet periods. - FAST_RETRY_CHECK_INTERVAL_MS (2s) immediately after a cycle that found retries — picks up subsequent backoff windows quickly without a full 10s wait. processRetries() now returns boolean so the scheduler can read the result. Shutdown guard (isShuttingDown) prevents re-scheduling after destroy.
18d5768 to
85bb896
Compare
KIvanow
requested changes
May 14, 2026
Member
KIvanow
left a comment
There was a problem hiding this comment.
Hey @Vswaroop04 - good idea and the implementation logic is sound, but I can't merge this without test coverage on the new scheduling behaviour. A few things to address:
- Tests for the adaptive loop. The schedule closure, the isShuttingDown guard, and the error-path fallback to BASE are all untested. Jest fake timers + a spy on processRetries returning true/false/rejecting would cover the three cases without spinning real timers.
- Check off the test plan. Please confirm pnpm test is green and the manual retry paths were verified before marking ready for review.
- Minor cleanup. The initial run and the schedule inner function have identical .then()/.catch() chains written out twice. Consider calling schedule(0) for the initial kick-off instead - one code path, fully testable.
- Replace duplicated initial-run chain with schedule(0) - Add fake-timer tests covering FAST/BASE scheduling, isShuttingDown guard, and error-path fallback to BASE interval
Contributor
Author
Done |
1a4c3d0 to
339af3b
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.
Summary
setInterval(10s)with asetTimeout-based self-scheduling loopprocessRetries()to return abooleanindicating whether any deliveries were foundisShuttingDownflag to prevent re-scheduling afteronModuleDestroyWhy
Webhook retries follow an exponential backoff pattern with short initial delays (1s, 2s, 4s). With the previous fixed 10s polling interval, retries could sit idle for up to 10 seconds before being processed.
This adaptive approach reduces that delay during active retry periods while maintaining the same database load during idle periods.
Test Plan
pnpm testand confirm existing webhook tests pass