Skip to content

Commit 917c2f6

Browse files
authored
fix: Retry webhooks only for 5xx (#665)
1 parent b5dd826 commit 917c2f6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/utils/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export const env = createEnv({
9494
// In testing, 100k transactions consumes ~300mb memory.
9595
TRANSACTION_HISTORY_COUNT: z.coerce.number().default(100_000),
9696
// Sets the number of recent completed jobs in each queue.
97-
QUEUE_COMPLETE_HISTORY_COUNT: z.coerce.number().default(10_000),
97+
QUEUE_COMPLETE_HISTORY_COUNT: z.coerce.number().default(2_000),
9898
// Sets the number of recent failed jobs in each queue.
9999
// These limits are higher to debug failed jobs.
100-
QUEUE_FAIL_HISTORY_COUNT: z.coerce.number().default(25_000),
100+
QUEUE_FAIL_HISTORY_COUNT: z.coerce.number().default(20_000),
101101
// Sets the number of recent nonces to map to queue IDs.
102102
NONCE_MAP_COUNT: z.coerce.number().default(10_000),
103103
},

src/worker/tasks/sendWebhookWorker.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
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";
33
import superjson from "superjson";
44
import { TransactionDB } from "../../db/transactions/db";
55
import { WebhooksEventTypes } from "../../schema/webhooks";
66
import { toEventLogSchema } from "../../server/schemas/eventLog";
77
import {
8-
TransactionSchema,
98
toTransactionSchema,
9+
type TransactionSchema,
1010
} from "../../server/schemas/transaction";
1111
import { toTransactionReceiptSchema } from "../../server/schemas/transactionReceipt";
1212
import { redis } from "../../utils/redis/redis";
13-
import { WebhookResponse, sendWebhookRequest } from "../../utils/webhook";
13+
import { sendWebhookRequest, type WebhookResponse } from "../../utils/webhook";
1414
import { logWorkerExceptions } from "../queues/queues";
15-
import { SendWebhookQueue, WebhookJob } from "../queues/sendWebhookQueue";
15+
import { SendWebhookQueue, type WebhookJob } from "../queues/sendWebhookQueue";
1616

1717
const handler: Processor<any, void, string> = async (job: Job<string>) => {
1818
const { data, webhook } = superjson.parse<WebhookJob>(job.data);
@@ -59,8 +59,9 @@ const handler: Processor<any, void, string> = async (job: Job<string>) => {
5959
}
6060
}
6161

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.
6465
throw new Error(
6566
`Received status ${resp.status} from webhook ${webhook.url}.`,
6667
);

0 commit comments

Comments
 (0)