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.

edit cron

Steven Tey108e382f8ed0
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.ts
index 76292d7100..210fde3f82 100644
--- a/apps/web/app/api/cron/usage/utils.ts
+++ b/apps/web/app/api/cron/usage/utils.ts
@@ -17,16 +17,9 @@ const limit = 100;
export const updateUsage = async () => {
const workspaces = await prisma.project.findMany({
where: {
- OR: [
- {
- usageLastChecked: {
- lt: new Date(new Date().getTime() - 24 * 60 * 60 * 1000), // 24 hours ago
- },
- },
- {
- usageLastChecked: null,
- },
- ],
+ usageLastChecked: {
+ lt: new Date(new Date().getTime() - 12 * 60 * 60 * 1000), // 12 hours ago
+ },
domains: {
some: {
verified: true,
@@ -47,6 +40,7 @@ export const updateUsage = async () => {
sentEmails: true,
},
orderBy: {
+ usageLastChecked: "asc",
createdAt: "asc",
},
take: limit,
@@ -57,18 +51,6 @@ export const updateUsage = async () => {
return;
}
- // Update usageLastChecked for workspaces
- await prisma.project.updateMany({
- where: {
- id: {
- in: workspaces.map(({ id }) => id),
- },
- },
- data: {
- usageLastChecked: new Date(),
- },
- });
-
// Reset billing cycles for workspaces that have
// adjustedBillingCycleStart that matches today's date
const billingReset = workspaces.filter(
@@ -249,6 +231,18 @@ export const updateUsage = async () => {
}),
);
+ // Update usageLastChecked for workspaces
+ await prisma.project.updateMany({
+ where: {
+ id: {
+ in: workspaces.map(({ id }) => id),
+ },
+ },
+ data: {
+ usageLastChecked: new Date(),
+ },
+ });
+
return await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/usage`,
method: "GET",