Improve naming of product sync hooks
This commit is contained in:
@@ -21,9 +21,9 @@ export type ProductSyncerOptions = {
|
||||
filter?: {
|
||||
pProductIds: number[] | null;
|
||||
},
|
||||
onStart?: (startDate: Date) => Promise<void>
|
||||
onCompletion?: (completionDate: Date, duration: number) => Promise<void>
|
||||
onStep?: (pProductIds: number[]) => Promise<void>
|
||||
beforeStart?: (startDate: Date) => Promise<void>
|
||||
afterCompletion?: (completionDate: Date, duration: number) => Promise<void>
|
||||
beforeStep?: (pProductIds: number[]) => Promise<void>
|
||||
};
|
||||
|
||||
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<Webflow.Products.Skus.Sku>[] = this.generateWSkus(pMetaProduct);
|
||||
const foundColors = new Set<string>(
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user