Skip to content

Conversation

@OmerHarell
Copy link
Collaborator

@OmerHarell OmerHarell commented Jun 25, 2025

  • Make queue service abstract
  • One place for monitoring
  • Inject redis

Summary by CodeRabbit

  • New Features

    • Introduced Redis integration for improved queue management and monitoring capabilities.
    • Added a unified interface for queue operations, streamlining job scheduling and worker registration.
  • Refactor

    • Simplified queue and worker setup, reducing dependencies and improving error handling.
    • Updated job retry and backoff configurations for more efficient processing.
    • Streamlined module structure and removed unused middleware and monitoring integrations.
    • Enhanced error logging and handling in job processing workflows.
    • Consolidated queue creation and registration with monitoring and UI services.
    • Refined webhook queue handling with improved job processing and error management.
    • Adjusted feature flag checks to ensure explicit control over webhook queue system usage.
  • Chores

    • Changed environment variable for worker port configuration.

… port config

- Remove MetricsAuthMiddleware configuration from WorkerAppModule
- Change retrieved port from 'PORT' to 'WORKER_PORT' in main.worker.ts
- Update BullBoardAuthMiddleware usage in WebhooksModule configuration
- Remove Redis connection initialization from constructor
- Inject Redis client through dependency injection
- Improve code structure by eliminating unnecessary methods
…ports

- Remove redundant queue registration lines in AlertQueueService
- Integrate BullBoard instance creation within QueueModule
- Simplify dependency handling in WebhooksService and related modules
- Simplify dependency injection for services in AlertQueueService
- Replace queue setup logic with createQueue method and refactor worker processing
- Eliminate unused code and streamline error handling in webhook job processing
- Add job scheduling setup for alert-check jobs with specific intervals
- Update relevant imports and refactor the QueueService to utilize RedisService
- Enhance IQueueService interface with additional documentation and job-related methods
@OmerHarell OmerHarell requested a review from alonp99 June 25, 2025 10:44
@OmerHarell OmerHarell self-assigned this Jun 25, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jun 25, 2025

⚠️ No Changeset found

Latest commit: 89b2632

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Walkthrough

This update refactors the queue management system by introducing a new Redis module and service, formalizing queue operations through an IQueueService interface, and consolidating queue-related dependencies. Queue setup, worker registration, and job scheduling are streamlined, with improved error handling and explicit queue creation. Bull Board integration and middleware usage are revised.

Changes

File(s) Change Summary
src/alert/alert-queue.service.ts, src/webhooks/webhooks.service.ts Refactored to use IQueueService for queue operations, simplified queue/job setup, improved error handling, and removed direct Prometheus/BullBoard registration.
src/common/queue/queue.service.ts Renamed QueueService to BullMQQueueService, implements IQueueService, explicit queue creation, simplified Redis handling, new addJob method, revised worker/job scheduler logic.
src/common/queue/types.ts Added IQueueService and QueueOptions interfaces for structured queue service contracts and configuration.
src/common/queue/queue.module.ts Updated providers to use BullMQQueueService, added Redis and monitoring modules, introduced Bull Board provider, and updated exports.
src/common/queue/queue-bullboard.service.ts Removed bulk registerQueues method, retained single queue registration with duplicate check.
src/common/redis/redis.module.ts, src/common/redis/redis.service.ts Introduced RedisModule and RedisService for Redis client management, including lifecycle handling and dependency injection.
src/app.worker.module.ts Removed middleware and related configuration, leaving an empty module class.
src/webhooks/webhooks.module.ts Removed Bull Board provider and middleware, simplified to only provide and export WebhooksService.
src/main.worker.ts Changed environment variable for port from PORT to WORKER_PORT.
src/events/document-changed-webhook-caller.ts, src/events/workflow-completed-webhook-caller.ts, src/events/workflow-state-changed-webhook-caller.ts Added retrieval of features property when fetching customer data and refined logic to determine forceDirect flag based on strict boolean check of WEBHOOK_QUEUE_SYSTEM_ENABLED feature flag.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant IQueueService
    participant RedisService
    participant Worker

    App->>IQueueService: createQueue(queueName, options)
    IQueueService->>RedisService: (uses Redis client)
    App->>IQueueService: addJob(queueName, jobName, data)
    IQueueService->>RedisService: (enqueue job)
    App->>IQueueService: registerWorker(queueName, processor)
    IQueueService->>Worker: (register processor)
    Worker->>IQueueService: process job
    IQueueService->>App: (callback with result/error)
Loading

Possibly related PRs

Poem

In tunnels of code, the queues align,
Redis now hums, connections fine.
Workers await with eager ears,
To process jobs and calm our fears.
Refactored flows, interfaces new,
The rabbit hops—our work is through!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89ab61c and 89b2632.

📒 Files selected for processing (5)
  • services/workflows-service/src/alert/alert-queue.service.ts (3 hunks)
  • services/workflows-service/src/common/queue/queue.service.ts (3 hunks)
  • services/workflows-service/src/common/queue/types.ts (1 hunks)
  • services/workflows-service/src/common/redis/redis.service.ts (1 hunks)
  • services/workflows-service/src/webhooks/webhooks.service.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • services/workflows-service/src/common/queue/types.ts
  • services/workflows-service/src/common/redis/redis.service.ts
  • services/workflows-service/src/alert/alert-queue.service.ts
  • services/workflows-service/src/webhooks/webhooks.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
`services/workflows-service/**/*.service.ts`: Service implementation files must be placed in feature modules and named with the .service.ts suffix.

services/workflows-service/**/*.service.ts: Service implementation files must be placed in feature modules and named with the .service.ts suffix.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/workflows-service.mdc)

List of files the instruction was applied to:

  • services/workflows-service/src/common/queue/queue.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: test_linux
  • GitHub Check: lint
  • GitHub Check: spell_check
  • GitHub Check: format
🔇 Additional comments (10)
services/workflows-service/src/common/queue/queue.service.ts (10)

1-10: LGTM! Clean dependency injection setup.

The imports are well-organized and the new dependencies (RedisService, BullMQPrometheusService, QueueBullboardService) support the refactoring objectives of centralizing monitoring and abstracting the queue service.


11-16: LGTM! Sensible default job options.

The default job options provide reasonable retry behavior (3 attempts with exponential backoff) and cleanup policies (keep 100 completed jobs for 7 days, retain failed jobs).


19-20: LGTM! Proper interface implementation and nullable Redis client.

The class correctly implements the IQueueService interface as intended by the refactoring. The nullable redisClient type allows for proper error handling during initialization.


33-43: LGTM! Simplified Redis client injection.

The constructor properly injects the RedisService and other monitoring dependencies, simplifying Redis client management as intended by the refactoring.


61-65: LGTM! Addresses previous validation concerns.

The validateQueueName method provides proper validation for queue names, addressing concerns from previous reviews about preventing empty or invalid queue names.


67-77: LGTM! Enforces explicit queue creation pattern.

The modified getQueue method now enforces explicit queue creation by throwing an error if the queue doesn't exist, which aligns with the refactoring goal of making queue management more intentional.


79-128: LGTM! Simplified worker registration with proper validation.

The refactored registerWorker method includes proper validation, simplified logic, and appropriate error handling. The removal of the return value and error-handling wrappers aligns with the intended simplification.


130-152: LGTM! Well-implemented explicit queue creation.

The createQueue method properly validates queue names, merges options, and integrates with monitoring services (Prometheus and BullBoard). This addresses the explicit queue creation requirement from the refactoring.


154-164: LGTM! Improved concurrent cleanup.

The onModuleDestroy method now handles worker and queue cleanup concurrently with proper error handling, which is more efficient than sequential cleanup.


166-204: LGTM! Enhanced scheduler setup with queue creation.

The setupJobScheduler method now accepts a queue name instead of a queue instance and creates the queue if it doesn't exist, which aligns with the explicit queue creation pattern. The validation and error handling are appropriate.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
services/workflows-service/src/common/queue/types.ts (1)

11-32: Consider using more specific types instead of any.

The interface uses any in several places. Consider:

  1. Making opts parameters more specific by defining job option interfaces
  2. Using generics more consistently across all methods
  3. Adding JSDoc documentation to clarify the purpose and usage of each method

Here's a more type-safe version:

+export interface JobOptions {
+  delay?: number;
+  priority?: number;
+  repeat?: { every: number };
+  // Add other common job options
+}
+
 export interface IQueueService {
-  addJob<T = any>(queueName: string, job_name: string, data: T, opts?: any): Promise<any>;
+  addJob<T = any, R = any>(queueName: string, job_name: string, data: T, opts?: JobOptions): Promise<R>;

   registerWorker<T = any>(
     queueName: string,
-    processor: (job: any) => Promise<any>,
+    processor: (job: { id: string; data: T; [key: string]: any }) => Promise<any>,
     options?: { concurrency?: number },
   ): void;

   isWorkerEnabled(): boolean;
   createQueue<T = any>(queueName: string, options?: QueueOptions<T>): void;
   setupJobScheduler<T = any>(
     queueName: string,
     schedulerId: string,
     scheduleOpts: { every: number },
     jobOpts: {
       name: string;
       data: T;
-      opts?: any;
+      opts?: JobOptions;
     },
-  ): Promise<any>;
+  ): Promise<void>;
 }
services/workflows-service/src/common/queue/queue.service.ts (1)

18-24: Fix parameter naming convention.

The parameter job_name should follow camelCase convention.

Apply this diff:

-  async addJob<T = any>(queueName: string, job_name: string, data: T, opts?: any): Promise<any> {
+  async addJob<T = any>(queueName: string, jobName: string, data: T, opts?: any): Promise<any> {
    const queue = this.getQueue(queueName);

-    return queue.add(job_name, data, {
+    return queue.add(jobName, data, {
      priority: opts?.priority,
    });
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8d1a2 and fed9014.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • services/workflows-service/src/alert/alert-queue.service.ts (3 hunks)
  • services/workflows-service/src/app.worker.module.ts (2 hunks)
  • services/workflows-service/src/common/queue/queue-bullboard.service.ts (0 hunks)
  • services/workflows-service/src/common/queue/queue.module.ts (1 hunks)
  • services/workflows-service/src/common/queue/queue.service.ts (3 hunks)
  • services/workflows-service/src/common/queue/types.ts (1 hunks)
  • services/workflows-service/src/common/redis/redis.module.ts (1 hunks)
  • services/workflows-service/src/common/redis/redis.service.ts (1 hunks)
  • services/workflows-service/src/main.worker.ts (1 hunks)
  • services/workflows-service/src/webhooks/webhooks.module.ts (2 hunks)
  • services/workflows-service/src/webhooks/webhooks.service.ts (6 hunks)
💤 Files with no reviewable changes (1)
  • services/workflows-service/src/common/queue/queue-bullboard.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
`services/workflows-service/**/*.service.ts`: Service implementation files must be placed in feature modules and named with the .service.ts suffix.

services/workflows-service/**/*.service.ts: Service implementation files must be placed in feature modules and named with the .service.ts suffix.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/workflows-service.mdc)

List of files the instruction was applied to:

  • services/workflows-service/src/alert/alert-queue.service.ts
  • services/workflows-service/src/common/redis/redis.service.ts
  • services/workflows-service/src/webhooks/webhooks.service.ts
  • services/workflows-service/src/common/queue/queue.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (14)
services/workflows-service/src/app.worker.module.ts (2)

7-7: Good consolidation of configuration imports.

Using only configs instead of both env and configs reduces redundancy and centralizes environment variable access.


15-39: Verify metrics and authentication still function after middleware removal.

The removal of MetricsAuthMiddleware configuration simplifies the module, but ensure that:

  1. Metrics collection is still working through other mechanisms
  2. Authentication/authorization is handled elsewhere if still needed

Run the following script to check if metrics middleware is configured elsewhere:

#!/bin/bash
# Description: Check if MetricsAuthMiddleware is used in other modules

# Search for MetricsAuthMiddleware usage
ast-grep --pattern 'MetricsAuthMiddleware'

# Check for alternative metrics middleware configuration
rg -A 5 "configure.*MiddlewareConsumer" --type ts
services/workflows-service/src/common/queue/types.ts (1)

34-47: Well-structured queue configuration options.

The QueueOptions interface provides comprehensive configuration including backoff strategies and retention policies. Good use of union types for backoff configuration.

services/workflows-service/src/main.worker.ts (1)

36-36: Good separation of worker port configuration.

Using WORKER_PORT instead of PORT allows the worker to run on a different port than the main application, improving deployment flexibility and debugging capabilities.

services/workflows-service/src/common/redis/redis.module.ts (1)

1-10: ```shell
#!/bin/bash

Refined search for the RedisService class definition

Try matching export with decorator using ast-grep

ast-grep --pattern $'@Injectable() export class RedisService { $$$ }'

Fallback: ripgrep in the redis.service.ts file

rg -n "class RedisService" -A 5 services/workflows-service/src/common/redis/redis.service.ts


</details>
<details>
<summary>services/workflows-service/src/alert/alert-queue.service.ts (3)</summary>

`16-20`: **Good use of dependency injection with interface token.**

The injection of `IQueueService` using the token pattern properly decouples this service from the concrete implementation.

---

`32-40`: **Verify the reduction in retry attempts is intentional.**

The number of retry attempts has been reduced from 10 to 3. This could impact reliability if alert checks frequently fail due to transient issues.

Was this reduction intentional? Consider if 3 retries are sufficient for your use case, especially for critical alert monitoring operations.

---

`65-76`: **Excellent error handling implementation.**

The dedicated `processAlertCheckJob` method with explicit try-catch error handling and logging improves observability and debugging. The error is properly re-thrown to allow the queue system to handle retries.

</details>
<details>
<summary>services/workflows-service/src/webhooks/webhooks.module.ts (1)</summary>

`11-25`: **LGTM! Module correctly simplified.**

The removal of Bull Board provider and authentication middleware aligns with the queue system refactoring. The module now correctly delegates Bull Board management to the QueueModule while still consuming the instance for route configuration.

</details>
<details>
<summary>services/workflows-service/src/common/redis/redis.service.ts (1)</summary>

`39-43`: **Add null check in onModuleDestroy.**

The method should check if the client exists before attempting to quit, especially since it can be null when the queue system is disabled.

Apply this diff:

```diff
  async onModuleDestroy() {
-    if (this.client) {
+    if (this.client && env.QUEUE_SYSTEM_ENABLED) {
      await this.client.quit();
    }
  }

Likely an incorrect or invalid review comment.

services/workflows-service/src/common/queue/queue.module.ts (1)

11-37: Well-structured module refactoring.

The module properly implements the dependency injection pattern with the IQueueService interface and centralizes Bull Board instance creation. The exports align with the new service structure.

services/workflows-service/src/webhooks/webhooks.service.ts (2)

59-67: Verify the reduction in retry attempts.

The retry attempts have been reduced to 3 (from what appears to be a higher default based on other parts of the codebase). Ensure this aligns with your webhook reliability requirements.


79-106: Good extraction of webhook processing logic.

Extracting the webhook processing into a separate method improves code organization and testability. The error handling with WebhookError provides better context for failures.

services/workflows-service/src/common/queue/queue.service.ts (1)

141-151: Robust cleanup implementation.

The concurrent cleanup of workers and queues with proper error handling ensures graceful shutdown.

- Remove unnecessary injection of BullBoard instance in AlertQueueService
- Update job options to reduce default attempts for better performance
- Enhance queue service methods for clearer job scheduling and worker registration
@OmerHarell OmerHarell force-pushed the bal-4425-bullmq-refactor branch from fed9014 to 9d128ef Compare June 25, 2025 10:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
services/workflows-service/src/common/queue/queue.service.ts (1)

115-139: Queue name validation is still missing.

The createQueue method still lacks validation for the queueName parameter as previously noted.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fed9014 and 9d128ef.

📒 Files selected for processing (7)
  • services/workflows-service/src/alert/alert-queue.service.ts (3 hunks)
  • services/workflows-service/src/common/queue/queue.module.ts (1 hunks)
  • services/workflows-service/src/common/queue/queue.service.ts (3 hunks)
  • services/workflows-service/src/common/queue/types.ts (1 hunks)
  • services/workflows-service/src/common/redis/redis.module.ts (1 hunks)
  • services/workflows-service/src/common/redis/redis.service.ts (1 hunks)
  • services/workflows-service/src/webhooks/webhooks.service.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • services/workflows-service/src/common/redis/redis.module.ts
  • services/workflows-service/src/common/queue/types.ts
  • services/workflows-service/src/alert/alert-queue.service.ts
  • services/workflows-service/src/common/redis/redis.service.ts
  • services/workflows-service/src/common/queue/queue.module.ts
  • services/workflows-service/src/webhooks/webhooks.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
`services/workflows-service/**/*.service.ts`: Service implementation files must be placed in feature modules and named with the .service.ts suffix.

services/workflows-service/**/*.service.ts: Service implementation files must be placed in feature modules and named with the .service.ts suffix.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/workflows-service.mdc)

List of files the instruction was applied to:

  • services/workflows-service/src/common/queue/queue.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test_linux
  • GitHub Check: Analyze (javascript)
  • GitHub Check: lint
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: format
  • GitHub Check: spell_check
🔇 Additional comments (7)
services/workflows-service/src/common/queue/queue.service.ts (7)

1-9: LGTM: Clean import organization.

The import changes properly reflect the new dependencies and abstractions introduced in the refactoring.


12-13: LGTM: Proper interface implementation and type refinement.

The class correctly implements the IQueueService interface and the Redis client type is appropriately refined.


28-31: LGTM: Proper dependency injection pattern.

The constructor properly injects the Redis service and initializes the client appropriately, following good DI practices.

Also applies to: 35-35


54-64: LGTM: Explicit queue management approach.

The change from implicit queue creation to explicit error throwing improves predictability and prevents accidental queue creation.


66-113: LGTM: Simplified worker registration.

The worker registration is properly streamlined while maintaining necessary error handling and logging.


141-151: LGTM: Improved concurrent cleanup.

The refactored cleanup logic properly handles both workers and queues concurrently with appropriate error handling.


153-192: LGTM: Simplified scheduler setup with appropriate defaults.

The method signature changes and simplified options structure improve usability while maintaining necessary functionality.

- Update forceDirect assignment to explicitly check for enabled state
- Ensure consistent behavior for document and workflow state changes
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
services/workflows-service/src/events/workflow-completed-webhook-caller.ts (1)

80-80: Consider clarifying the feature flag logic.

The conditional logic is functionally correct but may be confusing. The expression customer.features?.WEBHOOK_QUEUE_SYSTEM_ENABLED?.enabled !== true forces direct webhook calls when:

  • The feature is undefined/null
  • The feature exists but enabled is not strictly true

This means the queue system is only used when explicitly enabled (enabled === true), which appears intentional for the refactoring. However, the negative condition could be clearer.

Consider refactoring for better readability:

-        forceDirect: customer.features?.WEBHOOK_QUEUE_SYSTEM_ENABLED?.enabled !== true,
+        forceDirect: !customer.features?.WEBHOOK_QUEUE_SYSTEM_ENABLED?.enabled,

Or add a comment explaining the default behavior:

+        // Default to direct calls unless queue system is explicitly enabled
         forceDirect: customer.features?.WEBHOOK_QUEUE_SYSTEM_ENABLED?.enabled !== true,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d128ef and 9138011.

📒 Files selected for processing (3)
  • services/workflows-service/src/events/document-changed-webhook-caller.ts (2 hunks)
  • services/workflows-service/src/events/workflow-completed-webhook-caller.ts (1 hunks)
  • services/workflows-service/src/events/workflow-state-changed-webhook-caller.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: lint
  • GitHub Check: Analyze (javascript)
  • GitHub Check: spell_check
  • GitHub Check: test_linux
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: format
🔇 Additional comments (5)
services/workflows-service/src/events/document-changed-webhook-caller.ts (2)

87-87: LGTM! Feature flag access properly enabled.

Adding the features property to the select options enables access to customer feature flags, which is necessary for the queue system control logic implemented later in the file.


138-138: LGTM! Defensive queue system control implemented correctly.

The logic properly implements feature flag-based control over the webhook queue system:

  • Uses optional chaining to safely handle cases where features might not exist
  • Employs strict equality check (!== true) to ensure only explicitly enabled feature flags activate the queue system
  • Defaults to direct webhook calls (forceDirect: true) for safety, only using the queue when the feature is explicitly enabled

This defensive approach aligns well with the BullMQ refactor objectives and ensures reliable fallback behavior.

services/workflows-service/src/events/workflow-completed-webhook-caller.ts (1)

44-44: LGTM: Feature flag data retrieval added.

The addition of features: true to the select clause is appropriate for accessing customer feature flags that control queue behavior.

services/workflows-service/src/events/workflow-state-changed-webhook-caller.ts (2)

36-36: LGTM! Feature flags properly included in customer query.

Adding the features field to the select query enables access to customer feature flags, which is necessary for the updated webhook queue logic.


55-55: LGTM! Strict boolean checking ensures correct queue behavior.

The logic correctly implements strict boolean comparison (!== true) to ensure that only when the feature flag is explicitly set to boolean true will the queue system be used. All other cases (undefined, null, false, truthy non-boolean values) will default to direct sending, which provides a safe fallback behavior.

- Remove deprecated job option settings for consistency
- Introduce default job options in queue creation function
- Add validation to ensure valid queue names are provided
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.

3 participants