jobs: show target path in list rows; delete queued/finished jobs + clear-all history
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -8,13 +8,16 @@ import {
|
||||
getPipelineJobsForUser,
|
||||
getOldestPendingJob,
|
||||
countPendingJobs,
|
||||
deletePipelineJob,
|
||||
deleteTerminalJobsForUser,
|
||||
markInterruptedJobs,
|
||||
getUserById,
|
||||
} from 'officerdb';
|
||||
import { unlink } from 'node:fs/promises';
|
||||
import { toShellUsername } from '../../data-path';
|
||||
import { executePipeline } from './pipeline-executor';
|
||||
import type { OutMessage } from './pipeline-executor';
|
||||
import { executeScript, type ScriptEvent } from './execute-script';
|
||||
import { executeScript, jobLogPath, type ScriptEvent } from './execute-script';
|
||||
|
||||
// Everything a job can stream — pipeline structural events plus script stdout/stderr/exit.
|
||||
type JobEvent = OutMessage | ScriptEvent;
|
||||
@@ -318,6 +321,23 @@ export async function getJobsForUser(userId: number) {
|
||||
}));
|
||||
}
|
||||
|
||||
// Delete a job (row + log). Refuses a running job — it must be stopped first.
|
||||
export async function deleteJob(jobId: string): Promise<'deleted' | 'running' | 'noop'> {
|
||||
if (liveJobs.has(jobId)) return 'running';
|
||||
const job = await getPipelineJob(jobId);
|
||||
if (!job) return 'noop';
|
||||
await deletePipelineJob(jobId);
|
||||
await unlink(jobLogPath(jobId)).catch(() => {});
|
||||
return 'deleted';
|
||||
}
|
||||
|
||||
// Clear all finished jobs (rows + logs). Running/queued jobs are untouched.
|
||||
export async function clearHistory(userId: number): Promise<number> {
|
||||
const ids = await deleteTerminalJobsForUser(userId);
|
||||
await Promise.all(ids.map((id) => unlink(jobLogPath(id)).catch(() => {})));
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
// Lightweight header-badge summary: how many of the user's jobs are running / queued, and which one
|
||||
// is running (for the "running" badge's link).
|
||||
export async function getCounts(userId: number): Promise<{ running: number; runningJobId: string | null; queued: number }> {
|
||||
|
||||
Reference in New Issue
Block a user