Closed Dzeranov closed 58 minutes ago
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.
[x] Update WebhookIncomingEntity
model:
WebhookIncomingEntity
to WebhookEntity
.type
to WebhookEntity
with values: in
and out
.failedReason
field to store the reason for failed webhooks.url
field to store the webhook url.[x] Cron Module to track in
webhooks:
WebhookEntity
entries with type: in
and status pending
.escrowClient.complete()
.retriesCount
and retry the operation.[x] Create webhooks:
WebhookEntity
instances with type: out
and status pending
.[x] Update in
webhook status:
WebhookEntity
with type: in
to completed
.[x] Cron module to track out
webhooks:
WebhookEntity
entries with type: out
and status pending
.out
webhook:
webhookService.sendWebhook()
to send the notification.retriesCount
and store the failedReason
.in
webhook status to completed
.[x] Update migrations
[x] Update unit tests
Description Rework webhook processing by introducing new entities for better tracking and error handling. This includes adding a
WebhookOutgoingEntity
to manage outgoing webhooks, an EscrowCompletionTrackingEntity to track escrow status, and enhancing error handling mechanisms to prevent redundant operations and ensure failed webhooks are properly retried.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:
[x] Update
WebhookIncomingEntity
model:result_url
.PAID
status.failedReason
.retriesCount
.[x] Add
WebhookOutgoingEntity
model:id
,url
,payload (json)
,hash (url, payload)
,status (pending, sent)
,failedReason
,retriesCount
.[x] Add
EscrowCompletionTrakingEntity
model:id
,chain_id
,escrow_address
,final_results_url
,status (pending, paid, completed)
.[x] Cron Module to track incoming webhooks:
WebhookIncomingEntity
entries with statuspending
.EscrowCompletionTrakingEntity
with statuspending
.WebhookIncomingEntity
tocompleted
.[x] Cron Module to track escrow completion records:
EscrowCompletionTrakingEntity
entries with statuspaid
.Paid
, invokeescrowClient.complete()
.Partial
/Completed
, skip completion.WebhookOutgoingEntity
with statuspending
EscrowCompletionTrakingEntity
tocompleted
.[x] Cron Module to track escrow completion records:
EscrowCompletionTrakingEntity
entries with statuspending
.Launched
, invokeescrowClient.complete()
.result_url
exists.result_url
, execute payouts.Partial
, skip payouts.EscrowCompletionTrakingEntity
topaid
.[x] Cron Module to track outgoing webhooks:
WebhookOutgoingEntity
entries with statuspending
.WebhookIncomingEntity
tosent
.[x] Update migrations
[x] Update unit tests