Implement sync service queue
This commit is contained in:
+8
-11
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user