Cleanup terminology

This commit is contained in:
Dominic Ferrando
2026-07-12 01:43:55 -04:00
parent 80f8962a3b
commit 8b81156f6c
4 changed files with 46 additions and 37 deletions
+16 -14
View File
@@ -20,11 +20,11 @@ import { randomUUIDv7, sleep } from "bun";
import { CalculatorService, CalculatorUnavailableError } from "./services/calculator";
import { StandardsParamsSchema } from "@blade-and-brawn/calculator";
import { StandardsService } from "./services/standards";
import type { EventQueueService } from "./services/event-queue";
// CONSTANTS
// -----------------------
const EVENT_QUEUE_MANAGE_DELAY_MS = 1000 // 1 sec
const EVENT_QUEUE_CLEAN_DELAY_MS = 600000 // 10 min
// SERVICES
// -----------------------
@@ -194,9 +194,9 @@ export const app = new Elysia()
.group("/sync", (app) => app
// Sync status
.get("/", async ({ sessionId }) => {
const syncState = await s.Commerce.ProductSync.getSessionSyncState(sessionId);
if (!syncState) throw new NotFoundError("No product sync found for the provided session");
return syncState;
const latestSyncState = await s.Commerce.ProductSync.getLatestSyncState(sessionId);
if (!latestSyncState) throw new NotFoundError("No product sync found for the provided session");
return latestSyncState;
})
// Run sync
.post("/:pProductId?", async ({ params: { pProductId }, sessionId }) => {
@@ -317,16 +317,18 @@ app.listen(3000, async () => {
log.info({ port: 3000 }, "server started")
// MANAGE QUEUES
const queues = [s.Commerce.ProductSync.Queue];
while (true) {
for (const queue of queues) {
// clean, if ready
if ((Date.now() - queue.lastCleanDate.getTime()) >= EVENT_QUEUE_CLEAN_DELAY_MS)
await queue.clean();
// drain
await queue.drain().catch((err) => log.error(err));
}
await sleep(EVENT_QUEUE_MANAGE_DELAY_MS);
const queues: EventQueueService<any, any>[] = [s.Commerce.ProductSync.Queue];
for (const queue of queues) {
(async () => {
while (true) {
// clean, if ready
if ((Date.now() - queue.lastCleanDate.getTime()) >= queue.cfg.concurrency.timeoutMs)
await queue.clean().catch((err) => log.error(err));
// drain
await queue.drain().catch((err) => log.error(err));
await sleep(EVENT_QUEUE_MANAGE_DELAY_MS);
}
})();
}
}
});