From d40b9209d5de0f7cba237400db7e3569577d91b1 Mon Sep 17 00:00:00 2001 From: Dominic Ferrando Date: Sat, 11 Jul 2026 15:47:31 -0400 Subject: [PATCH] Improve naming of product sync hooks --- apps/api/src/services/commerce.ts | 8 ++++---- packages/commerce/src/sync.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/api/src/services/commerce.ts b/apps/api/src/services/commerce.ts index eef20c8..2109c72 100644 --- a/apps/api/src/services/commerce.ts +++ b/apps/api/src/services/commerce.ts @@ -47,19 +47,19 @@ class ProductSyncService { log.info({ session: payload.session }, "starting sync run"); await this.ProductSyncer.run({ filter: payload.filter, - onStart: async (startDate) => { + beforeStart: async (startDate) => { await this.Queue.enqueue(payload, startDate); }, - onStep: async (pProductIds: number[]) => { + beforeStep: async (pProductIds: number[]) => { if (!id) throw new Error("Expected sync run ID"); await db.updateTable("product_syncs") .set({ syncing_p_product_ids: pProductIds }) .where("id", "=", id) .execute(); }, - onCompletion: async (completionDate, duration) => { + afterCompletion: async (endDate, duration) => { if (!id) throw new Error("Expected sync run ID"); - await this.Queue.fulfill(id, completionDate) + await this.Queue.fulfill(id, endDate) freedSlot = true; } }); diff --git a/packages/commerce/src/sync.ts b/packages/commerce/src/sync.ts index 995742c..ba391c6 100644 --- a/packages/commerce/src/sync.ts +++ b/packages/commerce/src/sync.ts @@ -21,9 +21,9 @@ export type ProductSyncerOptions = { filter?: { pProductIds: number[] | null; }, - onStart?: (startDate: Date) => Promise - onCompletion?: (completionDate: Date, duration: number) => Promise - onStep?: (pProductIds: number[]) => Promise + beforeStart?: (startDate: Date) => Promise + afterCompletion?: (completionDate: Date, duration: number) => Promise + beforeStep?: (pProductIds: number[]) => Promise }; export class ProductSyncer { @@ -39,7 +39,7 @@ export class ProductSyncer { async run(opt: ProductSyncerOptions = {}) { const startDate = new Date(); - await opt.onStart?.(startDate); + await opt.beforeStart?.(startDate); if (opt.filter?.pProductIds) this.log.info({ pProductIds: opt.filter.pProductIds }, "sync started (filtered)"); @@ -58,7 +58,7 @@ export class ProductSyncer { for (const pMetaProduct of pMetaProducts) { const pProductIds = pMetaProduct.entries.map((e) => e.product.sync_product.id); this.log.info({ name: pMetaProduct.name, externalId: pMetaProduct.wProductId, pProductIds }, "syncing printful meta product"); - await opt.onStep?.(pProductIds); + await opt.beforeStep?.(pProductIds); const newWSkus: DeepPartial[] = this.generateWSkus(pMetaProduct); const foundColors = new Set( @@ -198,7 +198,7 @@ export class ProductSyncer { const endDate = new Date(); const duration = endDate.getTime() - startDate.getTime(); - await opt.onCompletion?.(endDate, duration); + await opt.afterCompletion?.(endDate, duration); this.log.info({ durationMs: duration }, "sync complete"); }