Add retries to processEvent handler with DB integration
This commit is contained in:
@@ -3,7 +3,12 @@
|
||||
import { onMount } from "svelte";
|
||||
import { api } from "$lib/api.js";
|
||||
|
||||
type SyncStatus = "pending" | "processing" | "failed" | "fulfilled";
|
||||
type SyncStatus =
|
||||
| "waiting"
|
||||
| "available"
|
||||
| "processing"
|
||||
| "failed"
|
||||
| "fulfilled";
|
||||
|
||||
const { data } = $props();
|
||||
|
||||
@@ -11,7 +16,11 @@
|
||||
status: "none" as SyncStatus | "none",
|
||||
syncingPProductIds: [] as number[],
|
||||
get isInProgress() {
|
||||
return this.status === "processing" || this.status === "pending";
|
||||
return (
|
||||
this.status !== "failed" &&
|
||||
this.status !== "fulfilled" &&
|
||||
this.status !== "none"
|
||||
);
|
||||
},
|
||||
poll: async function () {
|
||||
const res = await api.commerce.products.sync.get();
|
||||
@@ -20,8 +29,7 @@
|
||||
synchronizer.syncingPProductIds = [];
|
||||
} else {
|
||||
synchronizer.status = res.data.status;
|
||||
synchronizer.syncingPProductIds =
|
||||
res.data.syncingPProductIds;
|
||||
synchronizer.syncingPProductIds = res.data.syncingPProductIds;
|
||||
}
|
||||
},
|
||||
startPolling: () => {
|
||||
@@ -47,9 +55,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
const isProductSynced = async (
|
||||
pProduct: Printful.Products.SyncProduct,
|
||||
) => {
|
||||
const isProductSynced = async (pProduct: Printful.Products.SyncProduct) => {
|
||||
const wProducts = await data.products.webflow;
|
||||
return wProducts.some(
|
||||
(p) => p.product.id === pProduct.external_id.split("-")[0],
|
||||
@@ -88,8 +94,7 @@
|
||||
onclick={async () => {
|
||||
const res = await api.commerce
|
||||
.products({
|
||||
pProductId:
|
||||
pProduct.id,
|
||||
pProductId: pProduct.id,
|
||||
})
|
||||
.get();
|
||||
console.log(res.data);
|
||||
@@ -119,8 +124,7 @@
|
||||
<td>
|
||||
<button
|
||||
disabled={synchronizer.status === "processing"}
|
||||
onclick={() =>
|
||||
synchronizer.sync(pProduct.id)}
|
||||
onclick={() => synchronizer.sync(pProduct.id)}
|
||||
class="btn"
|
||||
>
|
||||
Sync
|
||||
|
||||
Reference in New Issue
Block a user