Fix bulk import stuck in pending state in dev mode
In dev (Vite), runKomootBulkImport was fire-and-forgotten with .catch(()=>{})
which silently swallowed all errors, leaving the batch frozen at "pending".
Fix:
- Pre-mark the batch as "running" before firing the detached promise so the
UI immediately transitions out of the pending state
- On failure, update the batch to "failed" with the error message instead of
swallowing it, so the UI shows the error and offers a retry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6a441675b9
commit
3af63c677f
1 changed files with 25 additions and 12 deletions
|
|
@ -67,22 +67,35 @@ export async function action({ request }: Route.ActionArgs) {
|
|||
status: "pending",
|
||||
});
|
||||
|
||||
// Try to enqueue via pg-boss (available in production / custom server).
|
||||
// In dev (Vite), boss is never initialized — fall back to running inline
|
||||
// in a detached promise so the response is still immediate.
|
||||
const { runKomootBulkImport } = await import("~/lib/komoot-bulk-import.server");
|
||||
const creds = service.credentials as Parameters<typeof runKomootBulkImport>[2];
|
||||
|
||||
// Try to enqueue via pg-boss (production / custom server.ts).
|
||||
// In dev (Vite), boss is never initialized — fall back to an inline
|
||||
// fire-and-forget so the redirect still happens immediately.
|
||||
let enqueued = false;
|
||||
try {
|
||||
const { getBoss } = await import("~/lib/boss.server");
|
||||
const boss = getBoss();
|
||||
await boss.send("komoot-bulk-import", {
|
||||
batchId,
|
||||
userId: user.id,
|
||||
creds: service.credentials,
|
||||
});
|
||||
await boss.send("komoot-bulk-import", { batchId, userId: user.id, creds });
|
||||
enqueued = true;
|
||||
} catch {
|
||||
const { runKomootBulkImport } = await import("~/lib/komoot-bulk-import.server");
|
||||
const creds = service.credentials as Parameters<typeof runKomootBulkImport>[2];
|
||||
// Fire-and-forget — don't await so the redirect happens immediately
|
||||
void runKomootBulkImport(batchId, user.id, creds).catch(() => {});
|
||||
// pg-boss not available
|
||||
}
|
||||
|
||||
if (!enqueued) {
|
||||
// Mark the batch running before returning so the UI doesn't stay frozen
|
||||
// if the detached promise fails to start.
|
||||
const { eq } = await import("drizzle-orm");
|
||||
await db.update(importBatches).set({ status: "running" }).where(eq(importBatches.id, batchId));
|
||||
void runKomootBulkImport(batchId, user.id, creds).catch(async (err) => {
|
||||
const { eq: eq2 } = await import("drizzle-orm");
|
||||
await db.update(importBatches).set({
|
||||
status: "failed",
|
||||
errorMessage: err instanceof Error ? err.message : String(err),
|
||||
completedAt: new Date(),
|
||||
}).where(eq2(importBatches.id, batchId));
|
||||
});
|
||||
}
|
||||
|
||||
return redirect("/sync/import/komoot");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue