Implement sync service queue

This commit is contained in:
Dominic Ferrando
2026-07-03 14:07:47 -04:00
parent fc9cd6f1ae
commit 437300831f
4 changed files with 99 additions and 37 deletions
+4 -5
View File
@@ -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))