From 1d7fc2cd03e7344fbcf285edddb65d21ab8808cd Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 24 Jan 2025 15:45:08 +0000 Subject: [PATCH] updated cron job --- server/package.json | 2 +- server/src/cron.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/package.json b/server/package.json index 261cf158d..c598b1dde 100644 --- a/server/package.json +++ b/server/package.json @@ -15,7 +15,7 @@ "prod:start": "node dist/src/index.js", "cron": "tsx src/cron.ts", - "cron:start": "tsc -b && tsx src/cron.ts", + "cron:start": "node --no-deprecation dist/src/cron.js", "clean": "tsx src/clean.ts" }, "author": "", diff --git a/server/src/cron.ts b/server/src/cron.ts index 25546f37b..2c57c17ac 100644 --- a/server/src/cron.ts +++ b/server/src/cron.ts @@ -12,6 +12,7 @@ import { getEntOptions } from "./internal/prices/priceUtils.js"; import { getNextResetAt } from "./utils/timeUtils.js"; import chalk from "chalk"; import { z } from "zod"; +import { format } from "date-fns"; dotenv.config(); const FullCustomerEntitlementWithProduct = FullCustomerEntitlementSchema.extend( @@ -73,14 +74,14 @@ const resetCustomerEntitlement = async ({ }, }); - console.log(`Successfull`); + console.log(`Successful`); } catch (error: any) { console.log("Error:", error.message || error); } }; export const cronTask = async () => { - console.log("RUNNING RESET CRON"); + console.log("RUNNING RESET CRON:", format(new Date(), "yyyy-MM-dd HH:mm:ss")); // 1. Query customer_entitlements for all customers with reset_interval < now const sb = createSupabaseClient(); let cusEntitlements: FullCustomerEntitlement[] = []; @@ -100,6 +101,12 @@ export const cronTask = async () => { } await Promise.all(resets); + + console.log( + "FINISHED RESET CRON:", + format(new Date(), "yyyy-MM-dd HH:mm:ss") + ); + process.exit(0); } catch (error) { console.error("Error getting entitlements for reset:", error); return;