Merge branch 'main' into staging

This commit is contained in:
John Yeo
2025-07-25 20:34:39 +01:00
4 changed files with 39 additions and 10 deletions

View File

@@ -9,14 +9,14 @@ import { resetCustomerEntitlement } from "./cron/cronUtils.js";
dotenv.config();
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 });
@@ -47,7 +47,7 @@ export const cronTask = async () => {
return;
}
await client.end();
// await client.end();
};
const job = new CronJob(
@@ -63,3 +63,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);
});

View File

@@ -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: "",
};
};

View File

@@ -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,
}),
})
);
}

View File

@@ -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();
});
});