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.

cron/cleanup syntax

Steven Teya94098c5c475
diff --git a/apps/web/app/(ee)/api/cron/cleanup/route.ts b/apps/web/app/(ee)/api/cron/cleanup/e2e-tests/route.ts
similarity index 97%
rename from apps/web/app/(ee)/api/cron/cleanup/route.ts
rename to apps/web/app/(ee)/api/cron/cleanup/e2e-tests/route.ts
index e9e18070de..2c82bc0132 100644
--- a/apps/web/app/(ee)/api/cron/cleanup/route.ts
+++ b/apps/web/app/(ee)/api/cron/cleanup/e2e-tests/route.ts
@@ -12,13 +12,12 @@ export const dynamic = "force-dynamic";
const E2E_USER_ID = "clxz1q7c7000hbqx5ckv4r82h";
const E2E_WORKSPACE_ID = "clrei1gld0002vs9mzn93p8ik";
-const E2E_PROGRAM_ID = "prog_CYCu7IMAapjkRpTnr8F1azjN";
/***
- This route is used to remove links, domains and tags created during the E2E test.
+ This route is used to remove links, domains and tags created during our E2E tests.
Runs every 6 hours (0 * / 6 * * *)
*/
-// GET /api/cron/cleanup
+// GET /api/cron/cleanup/e2e-tests
export async function GET(req: Request) {
try {
await verifyVercelSignature(req);
diff --git a/apps/web/app/(ee)/api/cron/link-retention-cleanup/route.ts b/apps/web/app/(ee)/api/cron/cleanup/link-retention/route.ts
similarity index 96%
rename from apps/web/app/(ee)/api/cron/link-retention-cleanup/route.ts
rename to apps/web/app/(ee)/api/cron/cleanup/link-retention/route.ts
index a66d48b21b..af46583ba3 100644
--- a/apps/web/app/(ee)/api/cron/link-retention-cleanup/route.ts
+++ b/apps/web/app/(ee)/api/cron/cleanup/link-retention/route.ts
@@ -12,8 +12,8 @@ import { z } from "zod";
export const dynamic = "force-dynamic";
// This route is used to delete old links for domains with linkRetentionDays set
-// Runs every minute (* * * * *)
-// GET /api/cron/link-retention-cleanup
+// Runs once a day at 00:00:00 UTC (0 0 * * *)
+// GET /api/cron/cleanup/link-retention
async function handler(req: Request) {
try {
if (req.method === "GET") {
@@ -143,7 +143,7 @@ async function deleteOldLinks(
// (indicating there might be more links to process)
if (processedBatches >= MAX_LINK_BATCHES && hasMoreLinks) {
await qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/link-retention-cleanup`,
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/cleanup/link-retention`,
method: "POST",
body: {
domain: domain.slug,
diff --git a/apps/web/lib/api/partners/bulk-delete-partners.ts b/apps/web/lib/api/partners/bulk-delete-partners.ts
index abeb55ef94..c4bc69d084 100644
--- a/apps/web/lib/api/partners/bulk-delete-partners.ts
+++ b/apps/web/lib/api/partners/bulk-delete-partners.ts
@@ -2,7 +2,7 @@ import { prisma } from "@dub/prisma";
import { bulkDeleteLinks } from "../links/bulk-delete-links";
// bulk delete multiple partners and all associated links, customers, payouts, and commissions
-// currently only used for the cron/cleanup job
+// currently only used for the cron/cleanup/e2e-tests job
export async function bulkDeletePartners({
partnerIds,
}: {
diff --git a/apps/web/lib/api/partners/delete-partner.ts b/apps/web/lib/api/partners/delete-partner.ts
index bc4876e16b..19f584bf7b 100644
--- a/apps/web/lib/api/partners/delete-partner.ts
+++ b/apps/web/lib/api/partners/delete-partner.ts
@@ -5,7 +5,7 @@ import { R2_URL } from "@dub/utils";
import { bulkDeleteLinks } from "../links/bulk-delete-links";
// delete partner and all associated links, customers, payouts, and commissions
-// currently only used for the cron/cleanup job
+// currently only used for the cron/cleanup/e2e-tests job
export async function deletePartner({ partnerId }: { partnerId: string }) {
const partner = await prisma.partner.findUnique({
where: {
diff --git a/apps/web/vercel.json b/apps/web/vercel.json
index af212e4fbd..6ce7e503f9 100644
--- a/apps/web/vercel.json
+++ b/apps/web/vercel.json
@@ -8,10 +8,6 @@
"path": "/api/cron/usage",
"schedule": "0 12 * * *"
},
- {
- "path": "/api/cron/cleanup",
- "schedule": "0 */6 * * *"
- },
{
"path": "/api/cron/disposable-emails",
"schedule": "0 12 * * 1"
@@ -49,8 +45,12 @@
"schedule": "0 0 * * *"
},
{
- "path": "/api/cron/link-retention-cleanup",
- "schedule": "* * * * *"
+ "path": "/api/cron/cleanup/e2e-tests",
+ "schedule": "0 */6 * * *"
+ },
+ {
+ "path": "/api/cron/cleanup/link-retention",
+ "schedule": "0 0 * * *"
}
],
"functions": {
diff --git a/packages/prisma/schema/link.prisma b/packages/prisma/schema/link.prisma
index 86f995f601..5601c2a911 100644
--- a/packages/prisma/schema/link.prisma
+++ b/packages/prisma/schema/link.prisma
@@ -89,5 +89,5 @@ model Link {
@@index([programId, partnerId]) // for getting a referral link (programId + partnerId)
@@index([domain, createdAt]) // for bulk link deletion workflows (by domain) + deleting old short-lived links
@@index(folderId) // used in /api/folders
- @@index(userId) // for relation to User table, used in /api/cron/cleanup too
+ @@index(userId) // for relation to User table, used in /api/cron/cleanup/e2e-tests too
}