Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move logic for calling webhook to separate queue #311

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

ghost
Copy link

@ghost ghost commented Aug 21, 2024

API PR Checklist

Pre-requisites

  • I have gone through the Contributing guidelines for Submitting a Pull Request (PR) and ensured that this is not a duplicate PR.
  • I have performed unit testing for the new feature added or updated to ensure the new features added are working as expected.
  • I have added/updated test cases to the test suite as applicable.
  • I have performed preliminary testing using the test suite to ensure that any existing features are not impacted and any new features are working as expected as a whole.
  • I have added/updated the required api docs as applicable.
  • I have added/updated the .env.example file with the required values as applicable.

PR Details

PR details have been updated as per the given format (see below)

  • PR title adheres to the format specified in guidelines (e.g., feat: add admin login endpoint)
  • Description has been added
  • Related changes have been added (optional)
  • Screenshots have been added (optional)
  • Query request and response examples have been added (as applicable, in case added or updated)
  • Documentation changes have been listed (as applicable)
  • Test suite/unit testing output is added (as applicable)
  • Pending actions have been added (optional)
  • Any other additional notes have been added (optional)

Additional Information

  • Appropriate label(s) have been added (ready for review should be added if the PR is ready to be reviewed)
  • Assignee(s) and reviewer(s) have been added (optional)

Note: Reviewer should ensure that the checklist and description have been populated and followed correctly, and the PR should be merged only after resolving all conversations and verifying that CI checks pass.


Description:

This PR moves the logic for sending webhook calls to a separate queue instead of handling it during the notification sending and provider confirmation itself.

Related changes:

  • Update notification.ts to add a WEBHOOK QueueAction
  • Update QueueService to add switch case for webhook related queues for providers, calling triggerWebhook
  • Update WebhookService and WebhookModule to to use NotificationsService for getting notification details from DB by ID, had some issues with circular dependencies, resolved them using forwardRef
  • Update NotificationConsumer to save notification and add notification to webhook queue for processing, wherever earlier webhook was being triggered directly
  • Update all provider consumers to import and pass in super method the NotificationQueueProducer

Screenshots:

N/A

Query request and response:

N/A

Documentation changes:

N/A

Test suite/unit testing output:

N/A

Pending actions:

N/A

Additional notes:

N/A

Summary by CodeRabbit

  • New Features

    • Added support for webhook notifications through the introduction of a new WEBHOOK action, enhancing the notification management system.
    • Introduced a queuing mechanism for notifications, improving processing reliability across multiple notification consumers.
  • Bug Fixes

    • Improved error handling by ensuring all notifications are processed consistently through the queue, regardless of delivery status.
  • Documentation

    • Updated module dependencies to allow for better interaction between the WebhookModule and NotificationsModule.
  • Refactor

    • Enhanced WebhookService to accept notification IDs instead of objects, streamlining webhook triggering processes.

Update notification.ts to add a WEBHOOK QueueAction
Update QueueService to add switch case for webhook related queues for providers, calling triggerWebhook
Update WebhookService and WebhookModule to to use NotificationsService for getting notification details from DB by ID, had some issues with circular dependencies, resolved them using forwardRef
Update NotificationConsumer to save notification and add notification to webhook queue for processing, wherever earlier webhook was being triggered directly
Update all provider consumers to import and pass in super method the NotificationQueueProducer
@ghost ghost added enhancement New feature or request ready for review labels Aug 21, 2024
@ghost ghost self-assigned this Aug 21, 2024
Copy link

coderabbitai bot commented Aug 21, 2024

Walkthrough

The changes introduce a new NotificationQueueProducer dependency across various consumer classes, enhancing the notification handling system. Additionally, a new WEBHOOK action is added to the QueueAction constants, allowing for better management of notifications via a queue. The WebhookService is also updated to streamline interaction with notifications, improving overall functionality and scalability of the notification processing system.

Changes

Files Change Summary
.../notifications.ts Added a new constant WEBHOOK to the QueueAction object, enhancing queue operations for webhook-related actions.
.../notifications/mailgun-notifications.job.consumer.ts, .../notifications/pushSns-notifications.job.consumer.ts, .../notifications/smsKapsystem-notifications.job.consumer.ts, .../notifications/smsPlivo-notifications.job.consumer.ts, .../notifications/smsTwilio-notifications.job.consumer.ts, .../notifications/vcTwilio-notifications.job.consumer.ts, .../notifications/wa360dialog-notifications.job.consumer.ts, .../notifications/waTwilio-notifications.job.consumer.ts, .../notifications/waTwilioBusiness-notifications.job.consumer.ts Updated constructors to inject NotificationQueueProducer, enhancing notification handling capabilities to interact with queues instead of immediate processing.
.../queues/queue.service.ts Introduced a new WebhookService dependency, expanding the service's functionality to manage various webhook actions and improve notification processing.
.../webhook/webhook.module.ts Modified imports to include NotificationsModule using forwardRef, enabling circular dependency resolution.
.../webhook/webhook.service.ts Injected NotificationsService to manage notifications; changed triggerWebhook to accept a notification ID rather than the full object, streamlining the process.

Sequence Diagram(s)

sequenceDiagram
    participant Producer as NotificationQueueProducer
    participant Consumer as NotificationConsumer
    participant Service as NotificationsService
    participant Webhook as WebhookService

    Consumer->>Producer: addNotificationToQueue(action, notification)
    Producer->>Service: save notification to repository
    Producer->>Webhook: triggerWebhook(id)
Loading

🐇 In the land where notifications hop,
A queue was built, so they never stop.
With webhooks dancing in the air,
Our messages soar, without a care!
So here’s to queues and wiggly tails,
Sending joy through all our trails! 🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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

Outside diff range, codebase verification and nitpick comments (4)
apps/api/src/jobs/consumers/notifications/wa360dialog-notifications.job.consumer.ts (1)

Unused Dependency: notificationsQueueService in Wa360dialogNotificationsConsumer

The notificationsQueueService is injected into the Wa360dialogNotificationsConsumer class but is not currently utilized within this class or its superclass NotificationConsumer. This could be an oversight or preparation for future functionality.

  • Consider reviewing the necessity of this dependency or ensuring its intended use is implemented.
Analysis chain

Line range hint 13-24: Dependency Injection: Verify the new dependency integration.

The NotificationQueueProducer is now injected into the Wa360dialogNotificationsConsumer class. Ensure that this new dependency is correctly utilized within the class.

Run the following script to verify the usage of notificationsQueueService within this class:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `notificationsQueueService` in `Wa360dialogNotificationsConsumer`.

# Test: Search for `notificationsQueueService` usage. Expect: At least one usage.
rg --type ts 'notificationsQueueService' -A 5

Length of output: 12572


Script:

#!/bin/bash
# Description: Search for methods in `Wa360dialogNotificationsConsumer` that use `notificationsQueueService`.

# Test: Search for `notificationsQueueService` usage within methods of `Wa360dialogNotificationsConsumer`.
ast-grep --lang typescript --pattern $'class Wa360dialogNotificationsConsumer extends $_ {
  $$$
  $_() {
    $$$
    this.notificationsQueueService.$_($$);
    $$$
  }
  $$$
}'

Length of output: 178


Script:

#!/bin/bash
# Description: Search for usage of `notificationsQueueService` in `NotificationConsumer`.

# Test: Search for `notificationsQueueService` usage within methods of `NotificationConsumer`.
ast-grep --lang typescript --pattern $'class NotificationConsumer {
  $$$
  $_() {
    $$$
    this.notificationsQueueService.$_($$);
    $$$
  }
  $$$
}'

Length of output: 155

apps/api/src/modules/webhook/webhook.service.ts (1)

38-41: Missing Method: getNotificationById not found in NotificationsService.

The getNotificationById method expected to be in the NotificationsService class does not exist in the codebase. This indicates a potential issue with the triggerWebhook method in webhook.service.ts, as it references a non-existent method.

  • Check the implementation of triggerWebhook in apps/api/src/modules/webhook/webhook.service.ts.
  • Verify the intended source and implementation of getNotificationById.
Analysis chain

Method Update: Verify notification retrieval by ID.

The triggerWebhook method now retrieves the notification using its ID. Ensure that the getNotificationById method returns the correct data.

Run the following script to verify the getNotificationById method's implementation and usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `getNotificationById` method in `NotificationsService`.

# Test: Search for `getNotificationById` method implementation. Expect: Correct retrieval logic.
ast-grep --lang typescript --pattern $'class NotificationsService {
  $$$
  getNotificationById($_) {
    $$$
  }
  $$$
}'

Length of output: 123


Script:

#!/bin/bash
# Search for the NotificationsService class in the codebase
ast-grep --lang typescript --pattern $'class NotificationsService { $$$ }'

Length of output: 2530


Script:

#!/bin/bash
# Search for any method named getNotificationById in the codebase
ast-grep --lang typescript --pattern $'function getNotificationById($_) { $$$ }'

Length of output: 81

apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts (1)

Dependency Injection Verification: notificationsQueueService Usage

The notificationsQueueService is injected into the WaTwilioNotificationsConsumer class but is only passed to the superclass constructor and not directly utilized within the class itself. Ensure that this service is intended to be used this way or consider adding logic to utilize it within the class if necessary.

  • File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts
Analysis chain

Line range hint 15-26: Dependency Injection: Verify the new dependency integration.

The NotificationQueueProducer is now injected into the WaTwilioNotificationsConsumer class. Ensure that this new dependency is correctly utilized within the class.

Run the following script to verify the usage of notificationsQueueService within this class:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `notificationsQueueService` in `WaTwilioNotificationsConsumer`.

# Test: Search for `notificationsQueueService` usage. Expect: At least one usage.
rg --type ts 'notificationsQueueService' -A 5

Length of output: 12572


Script:

#!/bin/bash
# Description: Verify specific usage of `notificationsQueueService` in `WaTwilioNotificationsConsumer`.

# Test: Search for `notificationsQueueService` usage within the WaTwilioNotificationsConsumer class.
ast-grep --lang typescript --pattern $'class WaTwilioNotificationsConsumer extends $_ {
  $$$
  notificationsQueueService: $_
  $$$
}' | xargs -I {} rg 'notificationsQueueService' -A 5 {}

Length of output: 190


Script:

#!/bin/bash
# Description: Find the file containing the WaTwilioNotificationsConsumer class and verify usage of notificationsQueueService.

# Find the file containing the class definition
file=$(rg --files-with-matches 'class WaTwilioNotificationsConsumer' --type ts)

# Search for notificationsQueueService usage within the identified file
if [ -n "$file" ]; then
  rg 'notificationsQueueService' -A 5 "$file"
else
  echo "WaTwilioNotificationsConsumer class not found."
fi

Length of output: 639

apps/api/src/jobs/consumers/notifications/smsPlivo-notifications.job.consumer.ts (1)

Dependency Injection: Unused Dependency in SmsPlivoNotificationsConsumer

The notificationsQueueService is injected into the SmsPlivoNotificationsConsumer class but is not directly used within the class. It is only passed to the superclass constructor. Consider reviewing its necessity or implementing its intended functionality.

  • apps/api/src/jobs/consumers/notifications/smsPlivo-notifications.job.consumer.ts
Analysis chain

Line range hint 15-26: Dependency Injection: Verify the new dependency integration.

The NotificationQueueProducer is now injected into the SmsPlivoNotificationsConsumer class. Ensure that this new dependency is correctly utilized within the class.

Run the following script to verify the usage of notificationsQueueService within this class:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `notificationsQueueService` in `SmsPlivoNotificationsConsumer`.

# Test: Search for `notificationsQueueService` usage. Expect: At least one usage.
rg --type ts 'notificationsQueueService' -A 5

Length of output: 12572


Script:

#!/bin/bash
# Description: Check for any usage of `notificationsQueueService` within `SmsPlivoNotificationsConsumer`.

# Test: Search for method calls or operations involving `notificationsQueueService`.
rg 'SmsPlivoNotificationsConsumer' -A 20 | rg 'notificationsQueueService'

Length of output: 324

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d47d23d and ec665e6.

Files selected for processing (15)
  • apps/api/src/common/constants/notifications.ts (1 hunks)
  • apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/notification.consumer.ts (5 hunks)
  • apps/api/src/jobs/consumers/notifications/pushSns-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/smsKapsystem-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/smsPlivo-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/smsTwilio-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/smtp-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/vcTwilio-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/wa360dialog-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/jobs/consumers/notifications/waTwilioBusiness-notifications.job.consumer.ts (2 hunks)
  • apps/api/src/modules/notifications/queues/queue.service.ts (3 hunks)
  • apps/api/src/modules/webhook/webhook.module.ts (1 hunks)
  • apps/api/src/modules/webhook/webhook.service.ts (3 hunks)
Additional context used
Learnings (10)
apps/api/src/jobs/consumers/notifications/smtp-notifications.job.consumer.ts (1)
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
apps/api/src/jobs/consumers/notifications/pushSns-notifications.job.consumer.ts (1)
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
apps/api/src/jobs/consumers/notifications/smsKapsystem-notifications.job.consumer.ts (1)
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
apps/api/src/jobs/consumers/notifications/wa360dialog-notifications.job.consumer.ts (2)
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-06-28T05:14:27.772Z
Learning: Error handling for `processWaTwilioNotificationQueue` is implemented in the superclass method, as pointed out by the user LakshayaT.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:32-55
Timestamp: 2024-06-28T05:15:55.671Z
Learning: Error handling for methods in `WaTwilioNotificationsConsumer` is managed by the superclass `NotificationConsumer`.
apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts (4)
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-06-28T05:14:27.772Z
Learning: Error handling for `processWaTwilioNotificationQueue` is implemented in the superclass method, as pointed out by the user LakshayaT.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:32-55
Timestamp: 2024-06-28T05:15:55.671Z
Learning: Error handling for methods in `WaTwilioNotificationsConsumer` is managed by the superclass `NotificationConsumer`.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-02T10:51:45.044Z
Learning: When refactoring code in the `WaTwilioNotificationsConsumer` class, unnecessary `else` clauses after `return` statements should be removed to simplify the control flow.
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
apps/api/src/jobs/consumers/notifications/vcTwilio-notifications.job.consumer.ts (4)
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-06-28T05:14:27.772Z
Learning: Error handling for `processWaTwilioNotificationQueue` is implemented in the superclass method, as pointed out by the user LakshayaT.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:32-55
Timestamp: 2024-06-28T05:15:55.671Z
Learning: Error handling for methods in `WaTwilioNotificationsConsumer` is managed by the superclass `NotificationConsumer`.
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-02T10:51:45.044Z
Learning: When refactoring code in the `WaTwilioNotificationsConsumer` class, unnecessary `else` clauses after `return` statements should be removed to simplify the control flow.
apps/api/src/jobs/consumers/notifications/smsTwilio-notifications.job.consumer.ts (2)
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-06-28T05:14:27.772Z
Learning: Error handling for `processWaTwilioNotificationQueue` is implemented in the superclass method, as pointed out by the user LakshayaT.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:32-55
Timestamp: 2024-06-28T05:15:55.671Z
Learning: Error handling for methods in `WaTwilioNotificationsConsumer` is managed by the superclass `NotificationConsumer`.
apps/api/src/jobs/consumers/notifications/waTwilioBusiness-notifications.job.consumer.ts (3)
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-06-28T05:14:27.772Z
Learning: Error handling for `processWaTwilioNotificationQueue` is implemented in the superclass method, as pointed out by the user LakshayaT.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:32-55
Timestamp: 2024-06-28T05:15:55.671Z
Learning: Error handling for methods in `WaTwilioNotificationsConsumer` is managed by the superclass `NotificationConsumer`.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/waTwilio-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-02T10:51:45.044Z
Learning: When refactoring code in the `WaTwilioNotificationsConsumer` class, unnecessary `else` clauses after `return` statements should be removed to simplify the control flow.
apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts (2)
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/modules/notifications/queues/queue.service.ts:87-87
Timestamp: 2024-07-03T08:38:36.915Z
Learning: The `processNotificationQueue` method in the `NotificationConsumer` class includes error handling, which covers the `processMailgunNotificationQueue` method in the `MailgunNotificationConsumer` class.
apps/api/src/jobs/consumers/notifications/notification.consumer.ts (2)
Learnt from: ayushnvs
PR: OsmosysSoftware/osmo-x#262
File: apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts:0-0
Timestamp: 2024-07-03T13:27:46.550Z
Learning: The `notificationSendResponse` variable in the `processMailgunNotificationConfirmationQueue` method of the `MailgunNotificationConsumer` class was changed from `let` to `const` to reflect that it is never reassigned.
Learnt from: LakshayaT
PR: OsmosysSoftware/osmo-x#263
File: apps/api/src/jobs/consumers/notifications/notification.consumer.ts:36-40
Timestamp: 2024-07-03T05:58:54.296Z
Learning: When reviewing retry mechanisms and delivery status updates, if the error object is already being logged, additional log messages for retry count and status might be redundant.
Additional comments not posted (12)
apps/api/src/modules/webhook/webhook.module.ts (1)

1-17: LGTM! Verify the use of forwardRef.

The use of forwardRef to resolve circular dependencies is appropriate.

However, ensure that the usage of forwardRef is consistent and correctly implemented across the codebase.

Run the following script to verify the usage of forwardRef:

Verification successful

Verification Successful: Consistent Use of forwardRef

The usage of forwardRef is consistent across the codebase, primarily in resolving circular dependencies within the webhook and notifications modules. No issues were found with its implementation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `forwardRef` in the codebase.

# Test: Search for all occurrences of `forwardRef`. Expect: Consistent usage across the codebase.
rg --type ts 'forwardRef'

Length of output: 4644

apps/api/src/common/constants/notifications.ts (1)

26-26: LGTM! Verify the usage of WEBHOOK.

The addition of WEBHOOK to the QueueAction object is appropriate.

However, ensure that the WEBHOOK action is utilized correctly in the codebase.

Run the following script to verify the usage of WEBHOOK:

Verification successful

WEBHOOK Usage Verified

The WEBHOOK action is correctly utilized in the codebase, both in queue operations and notification processing logic.

  • queue.service.ts: Handles various channel types and triggers webhooks appropriately.
  • notification.consumer.ts: Involved in notification processing logic.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `WEBHOOK` in the codebase.

# Test: Search for all occurrences of `WEBHOOK`. Expect: Correct usage in queue operations.
rg --type ts 'QueueAction.WEBHOOK'

Length of output: 1568


Script:

#!/bin/bash
# Check the context of `WEBHOOK` usage in queue.service.ts
rg --type ts -A 5 'QueueAction.WEBHOOK' apps/api/src/modules/notifications/queues/queue.service.ts

# Check the context of `WEBHOOK` usage in notification.consumer.ts
rg --type ts -A 5 'QueueAction.WEBHOOK' apps/api/src/jobs/consumers/notifications/notification.consumer.ts

Length of output: 1524

apps/api/src/jobs/consumers/notifications/smtp-notifications.job.consumer.ts (1)

Line range hint 11-32: LGTM! Verify the usage of NotificationQueueProducer.

The injection of NotificationQueueProducer into SmtpNotificationConsumer is appropriate.

However, ensure that NotificationQueueProducer is utilized correctly in the codebase.

Run the following script to verify the usage of NotificationQueueProducer:

Verification successful

Usage of NotificationQueueProducer is verified and correct.

The NotificationQueueProducer is used appropriately across the codebase, particularly in adding notifications to the queue with various actions. Its integration within consumer classes and services aligns with its intended functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer` in the codebase.

# Test: Search for all occurrences of `NotificationQueueProducer`. Expect: Correct usage in consumer classes.
rg --type ts 'NotificationQueueProducer'

Length of output: 5823


Script:

#!/bin/bash
# Description: Search for method calls or usages of `NotificationQueueProducer` in the codebase.

# Test: Search for all occurrences of method calls on `NotificationQueueProducer`. Expect: Correct usage in consumer classes.
rg --type ts 'notificationQueueService\.' -A 3

Length of output: 2154

apps/api/src/jobs/consumers/notifications/pushSns-notifications.job.consumer.ts (1)

Line range hint 10-31: LGTM! Verify the usage of NotificationQueueProducer.

The injection of NotificationQueueProducer into PushSnsNotificationConsumer is appropriate.

However, ensure that NotificationQueueProducer is utilized correctly in the codebase.

Run the following script to verify the usage of NotificationQueueProducer:

Verification successful

Correct Usage of NotificationQueueProducer Verified

The NotificationQueueProducer class is being utilized correctly across the codebase. The addNotificationToQueue method is called in various locations, including consumer classes and services, indicating its integration and usage are consistent with its intended purpose.

  • Files with method calls:
    • apps/api/src/modules/notifications/notifications.service.ts
    • apps/api/src/jobs/consumers/notifications/notification.consumer.ts

These calls confirm that the NotificationQueueProducer is actively used to add notifications to the queue, aligning with its design.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer` in the codebase.

# Test: Search for all occurrences of `NotificationQueueProducer`. Expect: Correct usage in consumer classes.
rg --type ts 'NotificationQueueProducer'

Length of output: 5823


Script:

#!/bin/bash
# Description: Extract methods where `NotificationQueueProducer` is used to verify correct utilization.

# Search for methods using `NotificationQueueProducer` in TypeScript files.
rg --type ts 'NotificationQueueProducer' -A 10

Length of output: 34911


Script:

#!/bin/bash
# Description: Verify calls to `addNotificationToQueue` method in the codebase.

# Search for calls to `addNotificationToQueue` method in TypeScript files.
rg --type ts 'addNotificationToQueue'

Length of output: 1026

apps/api/src/jobs/consumers/notifications/smsKapsystem-notifications.job.consumer.ts (1)

Line range hint 13-34: LGTM! Verify the usage of NotificationQueueProducer.

The injection of NotificationQueueProducer into SmsKapsystemNotificationsConsumer is appropriate.

However, ensure that NotificationQueueProducer is utilized correctly in the codebase.

Run the following script to verify the usage of NotificationQueueProducer:

Verification successful

Correct Usage of NotificationQueueProducer Verified

The NotificationQueueProducer is used appropriately in the codebase. It is primarily used to add notifications to a queue with specific actions, indicating correct utilization.

  • notifications.service.ts: Calls addNotificationToQueue with actions like SEND and DELIVERY_STATUS.
  • notification.consumer.ts: Calls addNotificationToQueue with the WEBHOOK action.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer` in the codebase.

# Test: Search for all occurrences of `NotificationQueueProducer`. Expect: Correct usage in consumer classes.
rg --type ts 'NotificationQueueProducer'

Length of output: 5823


Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer` methods or properties in the codebase.

# Test: Search for all occurrences of `NotificationQueueProducer` method or property usage.
rg --type ts 'notificationQueueService\.' -A 3

Length of output: 2154

apps/api/src/modules/webhook/webhook.service.ts (1)

17-18: Dependency Injection: Ensure circular dependency resolution.

The NotificationsService is injected using forwardRef to resolve circular dependencies. Verify that this approach is correctly implemented and does not introduce runtime issues.

Run the following script to check for any circular dependency issues:

Verification successful

Circular Dependency Resolution Verified

The use of forwardRef to inject NotificationsService is correctly implemented to resolve circular dependencies. There are no indications of runtime issues related to this setup. The implementation is consistent and follows best practices for dependency injection in the codebase.

  • forwardRef is used appropriately in the webhook.service.ts and other related files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify circular dependency resolution for `NotificationsService`.

# Test: Search for `forwardRef` usage related to `NotificationsService`. Expect: Correct usage without runtime issues.
rg --type ts 'forwardRef\(\s*\(\)\s*=>\s*NotificationsService\s*\)' -A 5

Length of output: 8436


Script:

#!/bin/bash
# Description: Check if NotificationsService uses forwardRef to inject any dependent services.

# Search for forwardRef usage within NotificationsService
rg --type ts 'forwardRef\(\s*\(\)\s*=>\s*' -A 5 | grep -B 5 'NotificationsService'

Length of output: 7068

apps/api/src/jobs/consumers/notifications/vcTwilio-notifications.job.consumer.ts (1)

Line range hint 15-26: Dependency Injection: Verify the new dependency integration.

The NotificationQueueProducer is now injected into the VcTwilioNotificationsConsumer class. Ensure that this new dependency is correctly utilized within the class.

Run the following script to verify the usage of notificationsQueueService within this class:

Verification successful

Dependency Injection: Verify the new dependency integration.

The notificationsQueueService is injected into the VcTwilioNotificationsConsumer class and passed to the superclass constructor. However, it is not directly used within the methods of this class. Ensure that this integration aligns with the intended design, especially if the superclass handles its usage.

  • Consider reviewing the superclass to ensure proper utilization of notificationsQueueService.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `notificationsQueueService` in `VcTwilioNotificationsConsumer`.

# Test: Search for `notificationsQueueService` usage. Expect: At least one usage.
rg --type ts 'notificationsQueueService' -A 5

Length of output: 12572


Script:

#!/bin/bash
# Description: Verify specific usage of `notificationsQueueService` in `VcTwilioNotificationsConsumer` class.

# Test: Search for `notificationsQueueService` usage within the class definition.
ast-grep --lang typescript --pattern $'class VcTwilioNotificationsConsumer extends $_ {
  $$$
  notificationsQueueService: $_
  $$$
}' -A 20

Length of output: 141


Script:

#!/bin/bash
# Description: Search for any usage of `notificationsQueueService` within the `VcTwilioNotificationsConsumer` class.

# Test: Locate `notificationsQueueService` usage in the specific file.
rg 'notificationsQueueService' apps/api/src/jobs/consumers/notifications/vcTwilio-notifications.job.consumer.ts -A 10

Length of output: 730

apps/api/src/jobs/consumers/notifications/smsTwilio-notifications.job.consumer.ts (1)

Line range hint 15-26: LGTM! Verify the integration of NotificationQueueProducer.

The addition of NotificationQueueProducer to the constructor looks good.

Ensure that NotificationQueueProducer is correctly integrated and utilized in the rest of the codebase.

Run the following script to verify the usage of NotificationQueueProducer in the codebase:

apps/api/src/jobs/consumers/notifications/waTwilioBusiness-notifications.job.consumer.ts (1)

Line range hint 15-26: LGTM! Verify the integration of NotificationQueueProducer.

The addition of NotificationQueueProducer to the constructor looks good.

Ensure that NotificationQueueProducer is correctly integrated and utilized in the rest of the codebase.

Run the following script to verify the usage of NotificationQueueProducer in the codebase:

apps/api/src/jobs/consumers/notifications/mailgun-notifications.job.consumer.ts (1)

Line range hint 13-24: LGTM! Verify the integration of NotificationQueueProducer.

The addition of NotificationQueueProducer to the constructor looks good.

Ensure that NotificationQueueProducer is correctly integrated and utilized in the rest of the codebase.

Run the following script to verify the usage of NotificationQueueProducer in the codebase:

Verification successful

Integration of NotificationQueueProducer Verified

The NotificationQueueProducer is correctly integrated and utilized across the codebase. It is consistently used to enqueue notifications for various actions, demonstrating its effective integration.

  • Usage Locations:
    • notifications.service.ts: Used for actions like SEND and DELIVERY_STATUS.
    • notification.consumer.ts: Used for WEBHOOK actions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer`.

# Test: Search for the usage of `NotificationQueueProducer`. Expect: Correct integration and usage.
rg --type ts 'NotificationQueueProducer'

Length of output: 5823


Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer` by checking for method calls or interactions.

# Search for method calls or interactions with `NotificationQueueProducer`
rg --type ts 'notificationQueueService\.' -A 5

Length of output: 3001

apps/api/src/jobs/consumers/notifications/notification.consumer.ts (1)

Line range hint 13-24: LGTM! Verify the integration of NotificationQueueProducer.

The addition of NotificationQueueProducer to the constructor and its usage in queuing notifications looks good.

Ensure that NotificationQueueProducer is correctly integrated and utilized in the rest of the codebase.

Run the following script to verify the usage of NotificationQueueProducer in the codebase:

Verification successful

Integration of NotificationQueueProducer Verified

The NotificationQueueProducer is correctly integrated and utilized in the codebase. It is used to add notifications to the queue in various parts of the application, such as in notifications.service.ts and notification.consumer.ts. The method addNotificationToQueue is called with appropriate parameters, indicating its intended functionality is being used.

  • Files with Usage:
    • apps/api/src/modules/notifications/notifications.service.ts
    • apps/api/src/jobs/consumers/notifications/notification.consumer.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NotificationQueueProducer`.

# Test: Search for the usage of `NotificationQueueProducer`. Expect: Correct integration and usage.
rg --type ts 'NotificationQueueProducer'

Length of output: 5823


Script:

#!/bin/bash
# Description: Verify method calls on instances of `NotificationQueueProducer`.

# Test: Search for method calls on `NotificationQueueProducer` instances.
rg --type ts '\bnotificationQueueService\.\w+\(' -A 3

Length of output: 2161

apps/api/src/modules/notifications/queues/queue.service.ts (1)

Line range hint 16-40: LGTM! Verify the integration of WebhookService.

The addition of WebhookService to the constructor and its usage in handling webhook actions looks good.

Ensure that WebhookService is correctly integrated and utilized in the rest of the codebase.

Run the following script to verify the usage of WebhookService in the codebase:

Verification successful

WebhookService Integration Verified

The WebhookService is correctly integrated and utilized in the codebase. It is actively used in various parts of the application, including the queue.service.ts and webhook.resolver.ts files, to handle webhook-related actions. No issues were found with its integration.

  • queue.service.ts: Used to trigger webhooks.
  • webhook.resolver.ts: Used to register webhooks.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `WebhookService`.

# Test: Search for the usage of `WebhookService`. Expect: Correct integration and usage.
rg --type ts 'WebhookService'

Length of output: 4412


Script:

#!/bin/bash
# Description: Verify the usage of `WebhookService` methods.

# Search for method calls or interactions with `WebhookService` in relevant files.
rg --type ts 'webhookService\.' -A 3

Length of output: 776

@xixas xixas merged commit 6606e17 into main Aug 21, 2024
6 checks passed
@xixas xixas deleted the feat/separate-webhook-queue branch August 21, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant