Small product sync naming cleanup
This commit is contained in:
@@ -7,7 +7,7 @@ import type { ProductSyncs } from "../database/out/db";
|
||||
|
||||
type SyncStatus = "queued" | "active" | "failed" | "succeeded";
|
||||
|
||||
type QueuedSync = {
|
||||
type QueuedProductSync = {
|
||||
id?: string,
|
||||
session: {
|
||||
name: string,
|
||||
@@ -29,30 +29,30 @@ export class CommerceService {
|
||||
token: env.WEBFLOW_AUTH,
|
||||
webhookSecret: env.WEBFLOW_WEBHOOK_SECRET,
|
||||
});
|
||||
readonly Sync = new SyncService(this.Printful, this.Webflow);
|
||||
readonly Sync = new ProductSyncService(this.Printful, this.Webflow);
|
||||
}
|
||||
|
||||
class SyncService {
|
||||
readonly Queue = new SyncQueueService();
|
||||
class ProductSyncService {
|
||||
readonly Queue = new ProductSyncQueueService();
|
||||
private readonly ProductSyncer: ProductSyncer;
|
||||
|
||||
constructor(private readonly Printful: PrintfulClient, private readonly Webflow: WebflowClient) {
|
||||
this.ProductSyncer = new ProductSyncer(this.Printful, this.Webflow, log);
|
||||
}
|
||||
|
||||
async start(queuedSync: QueuedSync) {
|
||||
let id = queuedSync.id ?? null;
|
||||
async start(queuedProductSync: QueuedProductSync) {
|
||||
let id = queuedProductSync.id ?? null;
|
||||
let freedSlot = false;
|
||||
try {
|
||||
log.info({ session: queuedSync.session }, "starting sync run");
|
||||
log.info({ session: queuedProductSync.session }, "starting sync run");
|
||||
await this.ProductSyncer.run({
|
||||
filter: queuedSync.filter,
|
||||
filter: queuedProductSync.filter,
|
||||
onStart: async (startDate) => {
|
||||
const values: Insertable<ProductSyncs> = {
|
||||
session_id: queuedSync.session.id,
|
||||
session_name: queuedSync.session.name,
|
||||
session_id: queuedProductSync.session.id,
|
||||
session_name: queuedProductSync.session.name,
|
||||
started_at: startDate,
|
||||
p_product_id_filter: queuedSync.filter?.pProductIds ?? null,
|
||||
p_product_id_filter: queuedProductSync.filter?.pProductIds ?? null,
|
||||
};
|
||||
if (id) {
|
||||
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 })
|
||||
.where("id", "=", activeSync.id)
|
||||
.execute();
|
||||
await this.start(queuedSync);
|
||||
await this.start(queuedProductSync);
|
||||
}
|
||||
else {
|
||||
log.info("sync already active, enqueuing next sync");
|
||||
await this.Queue.enqueue(queuedSync);
|
||||
await this.Queue.enqueue(queuedProductSync);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -168,17 +168,17 @@ class SyncService {
|
||||
}
|
||||
}
|
||||
|
||||
class SyncQueueService {
|
||||
async enqueue(queuedSync: QueuedSync) {
|
||||
class ProductSyncQueueService {
|
||||
async enqueue(queuedProductSync: QueuedProductSync) {
|
||||
const values: Insertable<ProductSyncs> = {
|
||||
session_id: queuedSync.session.id,
|
||||
session_name: queuedSync.session.name,
|
||||
p_product_id_filter: queuedSync.filter?.pProductIds ?? null
|
||||
session_id: queuedProductSync.session.id,
|
||||
session_name: queuedProductSync.session.name,
|
||||
p_product_id_filter: queuedProductSync.filter?.pProductIds ?? null
|
||||
};
|
||||
if (queuedSync.id) {
|
||||
if (queuedProductSync.id) {
|
||||
await db.updateTable("product_syncs")
|
||||
.set(values)
|
||||
.where("id", "=", queuedSync.id)
|
||||
.where("id", "=", queuedProductSync.id)
|
||||
.execute();
|
||||
}
|
||||
else {
|
||||
@@ -188,7 +188,7 @@ class SyncQueueService {
|
||||
}
|
||||
}
|
||||
|
||||
async front(): Promise<QueuedSync | undefined> {
|
||||
async front(): Promise<QueuedProductSync | undefined> {
|
||||
const result = await db.selectFrom("product_syncs")
|
||||
.selectAll()
|
||||
.where("started_at", "is", null)
|
||||
|
||||
Reference in New Issue
Block a user