Cleanup terminology
This commit is contained in:
+16
-14
@@ -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);
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user