Small product sync naming cleanup

This commit is contained in:
Dominic Ferrando
2026-07-04 16:38:20 -04:00
parent 28c5b3df18
commit 5c22640910
+21 -21
View File
@@ -7,7 +7,7 @@ import type { ProductSyncs } from "../database/out/db";
type SyncStatus = "queued" | "active" | "failed" | "succeeded"; type SyncStatus = "queued" | "active" | "failed" | "succeeded";
type QueuedSync = { type QueuedProductSync = {
id?: string, id?: string,
session: { session: {
name: string, name: string,
@@ -29,30 +29,30 @@ export class CommerceService {
token: env.WEBFLOW_AUTH, token: env.WEBFLOW_AUTH,
webhookSecret: env.WEBFLOW_WEBHOOK_SECRET, webhookSecret: env.WEBFLOW_WEBHOOK_SECRET,
}); });
readonly Sync = new SyncService(this.Printful, this.Webflow); readonly Sync = new ProductSyncService(this.Printful, this.Webflow);
} }
class SyncService { class ProductSyncService {
readonly Queue = new SyncQueueService(); readonly Queue = new ProductSyncQueueService();
private readonly ProductSyncer: ProductSyncer; private readonly ProductSyncer: ProductSyncer;
constructor(private readonly Printful: PrintfulClient, private readonly Webflow: WebflowClient) { constructor(private readonly Printful: PrintfulClient, private readonly Webflow: WebflowClient) {
this.ProductSyncer = new ProductSyncer(this.Printful, this.Webflow, log); this.ProductSyncer = new ProductSyncer(this.Printful, this.Webflow, log);
} }
async start(queuedSync: QueuedSync) { async start(queuedProductSync: QueuedProductSync) {
let id = queuedSync.id ?? null; let id = queuedProductSync.id ?? null;
let freedSlot = false; let freedSlot = false;
try { try {
log.info({ session: queuedSync.session }, "starting sync run"); log.info({ session: queuedProductSync.session }, "starting sync run");
await this.ProductSyncer.run({ await this.ProductSyncer.run({
filter: queuedSync.filter, filter: queuedProductSync.filter,
onStart: async (startDate) => { onStart: async (startDate) => {
const values: Insertable<ProductSyncs> = { const values: Insertable<ProductSyncs> = {
session_id: queuedSync.session.id, session_id: queuedProductSync.session.id,
session_name: queuedSync.session.name, session_name: queuedProductSync.session.name,
started_at: startDate, started_at: startDate,
p_product_id_filter: queuedSync.filter?.pProductIds ?? null, p_product_id_filter: queuedProductSync.filter?.pProductIds ?? null,
}; };
if (id) { if (id) {
const result = await db.updateTable("product_syncs") const result = await db.updateTable("product_syncs")
@@ -107,11 +107,11 @@ class SyncService {
.set({ syncing_p_product_ids: [], ended_at: new Date(), has_failed: true }) .set({ syncing_p_product_ids: [], ended_at: new Date(), has_failed: true })
.where("id", "=", activeSync.id) .where("id", "=", activeSync.id)
.execute(); .execute();
await this.start(queuedSync); await this.start(queuedProductSync);
} }
else { else {
log.info("sync already active, enqueuing next sync"); log.info("sync already active, enqueuing next sync");
await this.Queue.enqueue(queuedSync); await this.Queue.enqueue(queuedProductSync);
} }
} }
else { else {
@@ -168,17 +168,17 @@ class SyncService {
} }
} }
class SyncQueueService { class ProductSyncQueueService {
async enqueue(queuedSync: QueuedSync) { async enqueue(queuedProductSync: QueuedProductSync) {
const values: Insertable<ProductSyncs> = { const values: Insertable<ProductSyncs> = {
session_id: queuedSync.session.id, session_id: queuedProductSync.session.id,
session_name: queuedSync.session.name, session_name: queuedProductSync.session.name,
p_product_id_filter: queuedSync.filter?.pProductIds ?? null p_product_id_filter: queuedProductSync.filter?.pProductIds ?? null
}; };
if (queuedSync.id) { if (queuedProductSync.id) {
await db.updateTable("product_syncs") await db.updateTable("product_syncs")
.set(values) .set(values)
.where("id", "=", queuedSync.id) .where("id", "=", queuedProductSync.id)
.execute(); .execute();
} }
else { else {
@@ -188,7 +188,7 @@ class SyncQueueService {
} }
} }
async front(): Promise<QueuedSync | undefined> { async front(): Promise<QueuedProductSync | undefined> {
const result = await db.selectFrom("product_syncs") const result = await db.selectFrom("product_syncs")
.selectAll() .selectAll()
.where("started_at", "is", null) .where("started_at", "is", null)