Fix redis race condition

This commit is contained in:
Dominic Ferrando
2026-06-24 23:22:02 -04:00
parent 968afb5789
commit 51abbbc00c
3 changed files with 47 additions and 41 deletions
+6 -9
View File
@@ -126,22 +126,19 @@ export const app = new Elysia()
.group("/sync", (app) =>
app
// Sync status
.get("/", async ({ }) => await productSyncer.getState())
.get("/", async ({ }) => ({
state: await productSyncer.getState(),
isRunning: await productSyncer.isRunning()
}))
// Full sync
.post("/", async ({ }) => {
const syncState = await productSyncer.getState();
if (syncState.isSyncing)
if (!await productSyncer.sync())
throw status(409, "Sync already in progress");
await productSyncer.sync();
})
// Per-product sync
.post("/:printfulProductId", async ({ params }) => {
const syncState = await productSyncer.getState();
if (syncState.isSyncing)
if (!await productSyncer.sync(params.printfulProductId))
throw status(409, "Sync already in progress");
await productSyncer.sync(params.printfulProductId);
}, { params: z.object({ printfulProductId: z.coerce.number() }) }),
)
.get("/:printfulProductId", async ({ params }) => {