Skip to content

Conversation

@saby1101
Copy link
Member

@saby1101 saby1101 commented Jun 9, 2025

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 the randomDelay function, which introduces a randomized delay mechanism. The maximum delay can be configured using the EVENT_RANDOMIZED_DELAY_MAX environment variable. [1] [2]

Integration with Event Consumers:

@saby1101 saby1101 requested a review from Copilot June 9, 2025 12:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 randomDelay in utils.ts with a configurable EVENT_RANDOMIZED_DELAY_MAX
  • Integrates randomDelay into 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 randomDelay to 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 randomDelay to verify default behavior, custom max values, 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 max to maxDelay for 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 randomDelay is 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 randomDelay on 429/409 errors.
await randomDelay();

src/event-bus/event-consumer/azure-servicebus.ts:80

  • Add coverage for the Azure Service Bus consumer to confirm randomDelay is applied before abandoning messages on lock-conflict or rate-limit errors.
await randomDelay();

@saby1101 saby1101 merged commit 00591e4 into main Jun 9, 2025
1 check passed
@saby1101 saby1101 deleted the feature/random-delay branch June 9, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants