|
1 |
| -import { Static } from "@sinclair/typebox"; |
2 |
| -import { Job, Processor, Worker } from "bullmq"; |
| 1 | +import type { Static } from "@sinclair/typebox"; |
| 2 | +import { Worker, type Job, type Processor } from "bullmq"; |
3 | 3 | import superjson from "superjson";
|
4 | 4 | import { TransactionDB } from "../../db/transactions/db";
|
5 | 5 | import { WebhooksEventTypes } from "../../schema/webhooks";
|
6 | 6 | import { toEventLogSchema } from "../../server/schemas/eventLog";
|
7 | 7 | import {
|
8 |
| - TransactionSchema, |
9 | 8 | toTransactionSchema,
|
| 9 | + type TransactionSchema, |
10 | 10 | } from "../../server/schemas/transaction";
|
11 | 11 | import { toTransactionReceiptSchema } from "../../server/schemas/transactionReceipt";
|
12 | 12 | import { redis } from "../../utils/redis/redis";
|
13 |
| -import { WebhookResponse, sendWebhookRequest } from "../../utils/webhook"; |
| 13 | +import { sendWebhookRequest, type WebhookResponse } from "../../utils/webhook"; |
14 | 14 | import { logWorkerExceptions } from "../queues/queues";
|
15 |
| -import { SendWebhookQueue, WebhookJob } from "../queues/sendWebhookQueue"; |
| 15 | +import { SendWebhookQueue, type WebhookJob } from "../queues/sendWebhookQueue"; |
16 | 16 |
|
17 | 17 | const handler: Processor<any, void, string> = async (job: Job<string>) => {
|
18 | 18 | const { data, webhook } = superjson.parse<WebhookJob>(job.data);
|
@@ -59,8 +59,9 @@ const handler: Processor<any, void, string> = async (job: Job<string>) => {
|
59 | 59 | }
|
60 | 60 | }
|
61 | 61 |
|
62 |
| - if (resp && !resp.ok) { |
63 |
| - // Throw on non-2xx so it remains in the queue to retry later. |
| 62 | + const shouldRetry = resp && resp.status >= 500 && resp.status <= 599; |
| 63 | + if (shouldRetry) { |
| 64 | + // Throw on 5xx so it remains in the queue to retry later. |
64 | 65 | throw new Error(
|
65 | 66 | `Received status ${resp.status} from webhook ${webhook.url}.`,
|
66 | 67 | );
|
|
0 commit comments