Implement sync service queue

This commit is contained in:
Dominic Ferrando
2026-07-03 14:07:47 -04:00
parent fc9cd6f1ae
commit 437300831f
4 changed files with 99 additions and 37 deletions
+8 -11
View File
@@ -144,21 +144,18 @@ export const app = new Elysia()
app
// Sync status
.get("/", async ({ }) => {
const activeRun = await syncService.getActiveRun();
if (!activeRun) throw new NotFoundError("No sync in progress");
const activeSync = await syncService.getActiveSync();
if (!activeSync) throw new NotFoundError("No sync in progress");
return {
startDate: activeRun.started_at,
syncingPrintfulProductIds: activeRun.syncing_printful_product_ids
startDate: activeSync.started_at,
syncingPrintfulProductIds: activeSync.syncing_printful_product_ids
}
})
// Run sync
.post("/:printfulProductId?", async ({ params: { printfulProductId } }) => {
log.debug({ printfulProductId });
await syncService.start({
printfulProductIds: printfulProductId ?
[printfulProductId] :
undefined
});
const printfulProductIds = printfulProductId ? [printfulProductId] : null;
log.debug({ printfulProductIds });
await syncService.sync({ filter: { printfulProductIds } });
}, { params: t.Object({ printfulProductId: t.Optional(t.Numeric()) }) }),
)
.get("/:printfulProductId", async ({ params }) => {
@@ -185,7 +182,7 @@ export const app = new Elysia()
case Printful.Webhook.Event.ProductUpdated: {
const printfulProduct = payload.data.sync_product;
log.info({ productId: printfulProduct.id }, "printful webhook: product updated");
await syncService.start({ printfulProductIds: [printfulProduct.id] });
await syncService.sync({ filter: { printfulProductIds: [printfulProduct.id] } });
break;
}
case Printful.Webhook.Event.ProductDeleted: {