Implement sync service queue
This commit is contained in:
@@ -17,9 +17,9 @@ type MetaPrintfulProduct = {
|
||||
entries: ProductEntry[];
|
||||
};
|
||||
|
||||
export type SyncOptions = {
|
||||
export type ProductSyncerOptions = {
|
||||
filter?: {
|
||||
printfulProductIds?: number[];
|
||||
printfulProductIds: number[] | null;
|
||||
},
|
||||
onStart?: (startDate: Date) => Promise<void>
|
||||
onCompletion?: (completionDate: Date, duration: number) => Promise<void>
|
||||
@@ -37,8 +37,7 @@ export class ProductSyncer {
|
||||
this.log = (log ?? pino({ level: "silent" })).child({ component: "ProductSyncer" });
|
||||
}
|
||||
|
||||
async sync(opt: SyncOptions = {}) {
|
||||
this.log.info("starting sync run");
|
||||
async sync(opt: ProductSyncerOptions = {}) {
|
||||
const startDate = new Date();
|
||||
await opt.onStart?.(startDate);
|
||||
|
||||
@@ -256,7 +255,7 @@ export class ProductSyncer {
|
||||
async generateMetaPrintfulProducts(
|
||||
allWebflowProducts: Webflow.Products.ProductAndSkus[],
|
||||
allPrintfulProducts: Printful.Products.SyncProduct[],
|
||||
opt: SyncOptions,
|
||||
opt: ProductSyncerOptions,
|
||||
) {
|
||||
const metaNameFilter = opt.filter?.printfulProductIds
|
||||
?.map((id) => allPrintfulProducts.find((p) => p.id === id))
|
||||
|
||||
Reference in New Issue
Block a user