feat: add retry/delete for jobs
All checks were successful
Build & Push Docker Image / build-and-push (push) Successful in 41s
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:
@@ -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 });
|
||||
}
|
||||
|
||||
16
src/routes/api/jobs/[id]/retry/+server.ts
Normal file
16
src/routes/api/jobs/[id]/retry/+server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { getJob } from '$lib/server/db.js';
|
||||
import { retryJob } from '$lib/server/pipeline.js';
|
||||
|
||||
export async function POST({ params }) {
|
||||
const job = getJob(params.id);
|
||||
if (!job) throw error(404, 'Job not found');
|
||||
if (!['failed', 'cancelled'].includes(job.status)) {
|
||||
throw error(409, 'Only failed or cancelled jobs can be retried');
|
||||
}
|
||||
if (!job.source.startsWith('http')) {
|
||||
throw error(422, 'Cannot retry a file upload — please re-upload the file');
|
||||
}
|
||||
await retryJob(params.id);
|
||||
return json({ ok: true });
|
||||
}
|
||||
Reference in New Issue
Block a user