feat(event-bus): random-delay for 429 and 409 lock errors#1
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a randomized delay utility and wires it into all event consumers to improve backoff behavior on rate-limit and lock-conflict errors.
- Introduces
randomDelayinutils.tswith a configurableEVENT_RANDOMIZED_DELAY_MAX - Integrates
randomDelayinto RabbitMQ, GCP Pub/Sub, and Azure Service Bus consumers for 429/409 responses
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/event-bus/event-consumer/utils.ts | Defines RANDOMIZED_DELAY_MAX and randomDelay helper |
| src/event-bus/event-consumer/rabbitmq.ts | Imports and calls randomDelay() before requeue on 429/409 |
| src/event-bus/event-consumer/gcp-pubsub.ts | Imports and calls randomDelay() before nack on 429/409 |
| src/event-bus/event-consumer/azure-servicebus.ts | Imports and calls randomDelay() before abandon on 429/409 |
Comments suppressed due to low confidence (6)
src/event-bus/event-consumer/utils.ts:30
- Add a JSDoc comment above
randomDelayto describe its purpose, parameters, default behavior, and related environment variable.
export async function randomDelay(max: number = RANDOMIZED_DELAY_MAX) {
src/event-bus/event-consumer/utils.ts:30
- Add unit tests for
randomDelayto verify default behavior, custommaxvalues, and edge cases (e.g., zero or very large values).
export async function randomDelay(max: number = RANDOMIZED_DELAY_MAX) {
src/event-bus/event-consumer/utils.ts:30
- [nitpick] Consider renaming the parameter
maxtomaxDelayfor clearer intent in the function signature.
export async function randomDelay(max: number = RANDOMIZED_DELAY_MAX) {
src/event-bus/event-consumer/rabbitmq.ts:62
- Add or update integration tests for the RabbitMQ consumer to verify that
randomDelayis invoked correctly when handling 429/409 status codes.
await randomDelay();
src/event-bus/event-consumer/gcp-pubsub.ts:124
- Ensure GCP Pub/Sub consumer tests cover the retry path with
randomDelayon 429/409 errors.
await randomDelay();
src/event-bus/event-consumer/azure-servicebus.ts:80
- Add coverage for the Azure Service Bus consumer to confirm
randomDelayis applied before abandoning messages on lock-conflict or rate-limit errors.
await randomDelay();
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.
This pull request introduces a new utility function,
randomDelay, to improve handling of rate-limiting and lock-conflict scenarios across multiple event consumer implementations. The function is integrated into the Azure Service Bus, GCP Pub/Sub, and RabbitMQ consumer logic, and its maximum delay is configurable via an environment variable.Utility Enhancements:
src/event-bus/event-consumer/utils.ts: Added therandomDelayfunction, which introduces a randomized delay mechanism. The maximum delay can be configured using theEVENT_RANDOMIZED_DELAY_MAXenvironment variable. [1] [2]Integration with Event Consumers:
src/event-bus/event-consumer/azure-servicebus.ts: ImportedrandomDelayand integrated it into the Azure Service Bus consumer logic to handle rate-limiting and lock-conflict scenarios. [1] [2]src/event-bus/event-consumer/gcp-pubsub.ts: AddedrandomDelayto the GCP Pub/Sub consumer logic for similar scenarios. [1] [2]src/event-bus/event-consumer/rabbitmq.ts: IncorporatedrandomDelayinto the RabbitMQ consumer logic for handling rate-limiting and lock-conflict cases. [1] [2]