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

[Reputation Oracle] Refactor processPaidWebhooks method #2638

Open
7 tasks done
Dzeranov opened this issue Oct 15, 2024 · 0 comments
Open
7 tasks done

[Reputation Oracle] Refactor processPaidWebhooks method #2638

Dzeranov opened this issue Oct 15, 2024 · 0 comments
Assignees

Comments

@Dzeranov
Copy link
Contributor

Dzeranov commented Oct 15, 2024

Description
Need to rework processPaidWebhooks cron job.
Desired behaviour:
In case await escrowClient.complete() is successful we don't need to try complete the escrow again.
In case webhookService.sendWebhook() fails, we want to launch a cron job only for resending failed webhook(s).

My suggestion here is to implement some kind of a webhook queue because we are sending webhooks to multiple instances (JL, ExO, RecO) and we want to track which notification failed to be sent.

Motivation
With current implementation in case escrow has been successfully completed but webhook wasn't sent, cron job will be launched again trying to update escrow status to completed and this operation will fail causing webhook to be stuck.

Implementation details
Here’s a refined version of the implementation details with improved structure and clarity:


Implementation Details:

  • Update WebhookIncomingEntity model:

    • Rename WebhookIncomingEntity to WebhookEntity.
    • Add an enum field type to WebhookEntity with values: in and out.
    • Add a failedReason field to store the reason for failed webhooks.
    • Add a url field to store the webhook url.
  • Cron Module to track in webhooks:

    • Monitor WebhookEntity entries with type: in and status pending.
    • For each webhook, check the current escrow status:
      • If escrow is incomplete, invoke escrowClient.complete().
      • If escrow fails, increment retriesCount and retry the operation.
  • Create webhooks:

    • Generate three WebhookEntity instances with type: out and status pending.
  • Update in webhook status:

    • Update the status of the WebhookEntity with type: in to completed.
  • Cron module to track out webhooks:

    • Monitor WebhookEntity entries with type: out and status pending.
    • For each out webhook:
      • Use webhookService.sendWebhook() to send the notification.
      • If sending fails, increment retriesCount and store the failedReason.
      • Upon successful delivery, update the related in webhook status to completed.
  • Update migrations

  • Update unit tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

No branches or pull requests

2 participants