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:
@@ -79,6 +79,8 @@ export {
|
||||
getPipelineJobsForUser,
|
||||
getOldestPendingJob,
|
||||
countPendingJobs,
|
||||
deletePipelineJob,
|
||||
deleteTerminalJobsForUser,
|
||||
markInterruptedJobs,
|
||||
} from './queries/pipeline-jobs';
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { eq, and, asc, desc } from 'drizzle-orm';
|
||||
import { eq, and, inArray, asc, desc } from 'drizzle-orm';
|
||||
|
||||
const TERMINAL_STATUSES = ['completed', 'failed', 'stopped', 'interrupted'] as const;
|
||||
import { db } from '../db';
|
||||
import { pipelineJobs } from '../schema/pipeline-jobs';
|
||||
import type { PipelineJobInsert } from '../types';
|
||||
@@ -26,6 +28,20 @@ export async function getPipelineJobsForUser(userId: number, limit = 50) {
|
||||
.limit(limit);
|
||||
}
|
||||
|
||||
// Delete a single job row.
|
||||
export async function deletePipelineJob(id: string) {
|
||||
await db.delete(pipelineJobs).where(eq(pipelineJobs.id, id));
|
||||
}
|
||||
|
||||
// Delete all of a user's finished jobs (history); returns the deleted ids so their logs can be removed.
|
||||
export async function deleteTerminalJobsForUser(userId: number) {
|
||||
const rows = await db
|
||||
.delete(pipelineJobs)
|
||||
.where(and(eq(pipelineJobs.userId, userId), inArray(pipelineJobs.status, [...TERMINAL_STATUSES])))
|
||||
.returning({ id: pipelineJobs.id });
|
||||
return rows.map((r) => r.id);
|
||||
}
|
||||
|
||||
// Count of the user's queued (pending) jobs — for the header badge.
|
||||
export async function countPendingJobs(userId: number) {
|
||||
const rows = await db
|
||||
|
||||
Reference in New Issue
Block a user