Schedule configurable completed pricing-job cleanup in the worker, broaden repository cleanup across sellers, add unit and integration coverage, and update pricing operational documentation.
This commit is contained in:
@@ -22,6 +22,7 @@ import { createHttpPricingProvider } from "../../api/src/modules/pricing/provide
|
||||
import { processNextPersistentImageDerivativeJob } from "./image-derivative-worker.js";
|
||||
import {
|
||||
processNextPersistentPricingRefreshJob,
|
||||
purgeCompletedPricingRefreshJobs,
|
||||
runPricingRefreshJob,
|
||||
} from "./pricing-refresh-worker.js";
|
||||
|
||||
@@ -29,6 +30,14 @@ const pollIntervalMs = Number.parseInt(
|
||||
process.env.WORKER_POLL_INTERVAL_MS ?? "2000",
|
||||
10,
|
||||
);
|
||||
const pricingJobRetentionDays = Number.parseInt(
|
||||
process.env.PRICING_JOB_RETENTION_DAYS ?? "30",
|
||||
10,
|
||||
);
|
||||
const pricingJobCleanupIntervalMs = Number.parseInt(
|
||||
process.env.PRICING_JOB_CLEANUP_INTERVAL_MS ?? "3600000",
|
||||
10,
|
||||
);
|
||||
|
||||
async function runWorker() {
|
||||
const imageStorageRoot = resolveProjectImageStorageRoot(
|
||||
@@ -63,6 +72,15 @@ async function runWorker() {
|
||||
renderer: createSharpImageRenderer(),
|
||||
});
|
||||
|
||||
async function cleanupPricingJobs() {
|
||||
const deletedCount = await purgeCompletedPricingRefreshJobs({
|
||||
jobRepository: pricingRefreshJobRepository,
|
||||
retentionDays: pricingJobRetentionDays,
|
||||
});
|
||||
if (deletedCount > 0)
|
||||
console.log(`Purged ${deletedCount} completed pricing refresh job(s).`);
|
||||
}
|
||||
|
||||
async function processOne() {
|
||||
const result = await processNextPersistentImageDerivativeJob({
|
||||
jobRepository,
|
||||
@@ -94,13 +112,19 @@ async function runWorker() {
|
||||
}
|
||||
|
||||
await processOne();
|
||||
await cleanupPricingJobs();
|
||||
const timer = setInterval(
|
||||
() => processOne().catch((error) => console.error(error)),
|
||||
pollIntervalMs,
|
||||
);
|
||||
const cleanupTimer = setInterval(
|
||||
() => cleanupPricingJobs().catch((error) => console.error(error)),
|
||||
pricingJobCleanupIntervalMs,
|
||||
);
|
||||
|
||||
const shutdown = async () => {
|
||||
clearInterval(timer);
|
||||
clearInterval(cleanupTimer);
|
||||
await database.close();
|
||||
};
|
||||
process.once("SIGINT", shutdown);
|
||||
|
||||
Reference in New Issue
Block a user