Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update queue-discount-code-deletion.ts

Kiran K87aa84151b03
diff --git a/apps/web/lib/api/discounts/queue-discount-code-deletion.ts b/apps/web/lib/api/discounts/queue-discount-code-deletion.ts
index 2ee46d080d..fc59fddbef 100644
--- a/apps/web/lib/api/discounts/queue-discount-code-deletion.ts
+++ b/apps/web/lib/api/discounts/queue-discount-code-deletion.ts
@@ -1,5 +1,5 @@
import { qstash } from "@/lib/cron";
-import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
+import { APP_DOMAIN_WITH_NGROK, chunk } from "@dub/utils";
import { Discount } from "@prisma/client";
const queue = qstash.queue({
@@ -27,14 +27,18 @@ export async function queueDiscountCodeDeletion(
// TODO:
// Check if we can use the batchJSON (I tried it but didn't work)
- await Promise.allSettled(
- discountCodeIds.map((discountCodeId) =>
- queue.enqueueJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discount-codes/${discountCodeId}/delete`,
- method: "POST",
- }),
- ),
- );
+ const chunks = chunk(discountCodeIds, 100);
+
+ for (const chunkOfIds of chunks) {
+ await Promise.allSettled(
+ chunkOfIds.map((discountCodeId) =>
+ queue.enqueueJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discount-codes/${discountCodeId}/delete`,
+ method: "POST",
+ }),
+ ),
+ );
+ }
}
export function isDiscountEquivalent(