feat: add retry/delete for jobs
All checks were successful
Build & Push Docker Image / build-and-push (push) Successful in 41s

- db.ts: add resetJob() and deleteJob() statements + exports
- pipeline.ts: export retryJob() — resets job state and re-runs pipeline
- DELETE /api/jobs/[id]: hard-delete terminal jobs (done/failed/cancelled);
  keep cancel-only behavior for active jobs
- POST /api/jobs/[id]/retry: new endpoint; validates failed/cancelled URL job,
  resets and re-runs via retryJob()
- jobs/[id]/+page.svelte: wire Cancel/Retry/Delete buttons with fetch calls;
  fix hardcoded ACCENT → accent store
- jobs/+page.svelte: per-row Retry+Delete icon buttons (visible on hover);
  fix hardcoded ACCENT → accent store

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Giancarmine Salucci
2026-05-06 17:42:54 +02:00
parent 37175ec791
commit d1295ce343
6 changed files with 207 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import { json, error } from '@sveltejs/kit';
import { getJob, setJobStatus } from '$lib/server/db.js';
import { getJob, setJobStatus, deleteJob } from '$lib/server/db.js';
import { rm } from 'fs/promises';
export async function GET({ params }) {
const job = getJob(params.id);
@@ -7,12 +8,19 @@ export async function GET({ params }) {
return json(job);
}
const ACTIVE = new Set(['pending', 'downloading', 'preparing', 'transcribing', 'processing']);
export async function DELETE({ params }) {
const job = getJob(params.id);
if (!job) throw error(404, 'Job not found');
if (job.status === 'done' || job.status === 'failed') {
throw error(409, 'Job already completed');
if (ACTIVE.has(job.status)) {
// Cancel active job (keeps DB record)
setJobStatus(params.id, 'cancelled', 0);
} else {
// Hard-delete terminal job + clean up output files
deleteJob(params.id);
if (job.outputDir) rm(job.outputDir, { recursive: true, force: true }).catch(() => {});
}
setJobStatus(params.id, 'cancelled', 0);
return new Response(null, { status: 204 });
}