From ff83e561dbc33261f825ee919ddf8c820c2e249d Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 25 Jul 2025 15:48:25 +0100 Subject: [PATCH 1/4] fix: trigger checkout reward from checkout.completed --- server/tests/attach/free/free1.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/tests/attach/free/free1.ts b/server/tests/attach/free/free1.ts index 81ae30fb4..3c6539f9c 100644 --- a/server/tests/attach/free/free1.ts +++ b/server/tests/attach/free/free1.ts @@ -21,6 +21,8 @@ import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { addDays } from "date-fns"; import { expect } from "chai"; import { eq } from "drizzle-orm"; +import { CacheManager } from "@/external/caching/CacheManager.js"; +import { clearOrgCache } from "@/internal/orgs/orgUtils/clearOrgCache.js"; const testCase = "free1"; @@ -83,6 +85,12 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }) .where(eq(organizations.id, org.id)); + await clearOrgCache({ + db, + orgId: org.id, + env, + }); + const { testClockId: testClockId1 } = await initCustomer({ autumn: autumnJs, customerId, @@ -109,7 +117,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }); const approximateDiff = 1000 * 60 * 30; // 30 minutes - it("should attach pro product (prepaid single use)", async function () { + it("should attach free product with trial", async function () { let attachPreview = await autumn.attachPreview({ customer_id: customerId, product_id: free.id, @@ -191,5 +199,13 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }, }) .where(eq(organizations.id, org.id)); + + await clearOrgCache({ + db, + orgId: org.id, + env, + }); + + await CacheManager.disconnect(); }); }); From cac101434dfdc84905744260251e040be4f6fc06 Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 25 Jul 2025 17:22:50 +0100 Subject: [PATCH 2/4] fix: reduced max db connections on workers --- .../productResponseUtils/getProductItemDisplay.ts | 5 +++-- server/src/queue/workersInit.ts | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/src/internal/products/productUtils/productResponseUtils/getProductItemDisplay.ts b/server/src/internal/products/productUtils/productResponseUtils/getProductItemDisplay.ts index 52c38753d..0dc741e7c 100644 --- a/server/src/internal/products/productUtils/productResponseUtils/getProductItemDisplay.ts +++ b/server/src/internal/products/productUtils/productResponseUtils/getProductItemDisplay.ts @@ -180,8 +180,9 @@ export const getFeaturePriceItemDisplay = ({ } return { - primary_text: priceStr, - secondary_text: `per ${priceStr2}${intervalStr}`, + primary_text: priceStr + ` per ${priceStr2}${intervalStr}`, + // secondary_text: `per ${priceStr2}${intervalStr}`, + secondary_text: "", }; }; diff --git a/server/src/queue/workersInit.ts b/server/src/queue/workersInit.ts index 2d2db82ee..80cc2b670 100644 --- a/server/src/queue/workersInit.ts +++ b/server/src/queue/workersInit.ts @@ -23,7 +23,7 @@ const actionHandlers = [ JobName.HandleCustomerCreated, ]; -const { db, client } = initDrizzle({ maxConnections: 20 }); +const { db, client } = initDrizzle({ maxConnections: 10 }); const initWorker = ({ id, @@ -168,7 +168,7 @@ const initWorker = ({ }, drainDelay: 1000, maxStalledCount: 0, - }, + } ); worker.on("ready", () => { @@ -207,7 +207,7 @@ export const initWorkers = async () => { queue: mainQueue, useBackup: false, db, - }), + }) ); workers.push( initWorker({ @@ -216,7 +216,7 @@ export const initWorkers = async () => { useBackup: true, db, - }), + }) ); } From b910d45a2cb8994f51e5ce6090ce63546bf261de Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 25 Jul 2025 20:02:58 +0100 Subject: [PATCH 3/4] fix: using one db connection in cron --- server/src/cron.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/cron.ts b/server/src/cron.ts index 5b386713b..4add1f3aa 100644 --- a/server/src/cron.ts +++ b/server/src/cron.ts @@ -231,14 +231,14 @@ const resetCustomerEntitlement = async ({ } }; +const { db, client } = initDrizzle(); + export const cronTask = async () => { console.log( "\n----------------------------------\nRUNNING RESET CRON:", format(new UTCDate(), "yyyy-MM-dd HH:mm:ss") ); - const { db, client } = initDrizzle(); - try { let cusEnts: FullCusEntWithProduct[] = await CusEntService.getActiveResetPassed({ db, batchSize: 500 }); From 67a69ccf956c6d1aec00f0899475ecd10449e13f Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 25 Jul 2025 20:24:51 +0100 Subject: [PATCH 4/4] fix: closing client in cron.ts --- server/src/cron.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/cron.ts b/server/src/cron.ts index 4add1f3aa..5ccbae816 100644 --- a/server/src/cron.ts +++ b/server/src/cron.ts @@ -269,7 +269,7 @@ export const cronTask = async () => { return; } - await client.end(); + // await client.end(); }; const job = new CronJob( @@ -285,3 +285,15 @@ const job = new CronJob( // job.start(); cronTask(); + +process.on("SIGTERM", async () => { + console.log("Received SIGTERM signal, closing database connection..."); + await client.end(); + process.exit(0); +}); + +process.on("SIGINT", async () => { + console.log("Received SIGINT signal, closing database connection..."); + await client.end(); + process.exit(0); +});