Improve naming of product sync hooks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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