jobs: header running/queued badges + GET /jobs/counts (phase 3d)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 15:48:52 +00:00
co-authored by Claude Opus 4.8
parent c277ceead7
commit f77ce3fb96
7 changed files with 83 additions and 7 deletions
+1
View File
@@ -78,6 +78,7 @@ export {
updatePipelineJob,
getPipelineJobsForUser,
getOldestPendingJob,
countPendingJobs,
markInterruptedJobs,
} from './queries/pipeline-jobs';
@@ -1,4 +1,4 @@
import { eq, asc, desc } from 'drizzle-orm';
import { eq, and, asc, desc } from 'drizzle-orm';
import { db } from '../db';
import { pipelineJobs } from '../schema/pipeline-jobs';
import type { PipelineJobInsert } from '../types';
@@ -26,6 +26,15 @@ export async function getPipelineJobsForUser(userId: number, limit = 50) {
.limit(limit);
}
// Count of the user's queued (pending) jobs — for the header badge.
export async function countPendingJobs(userId: number) {
const rows = await db
.select({ id: pipelineJobs.id })
.from(pipelineJobs)
.where(and(eq(pipelineJobs.userId, userId), eq(pipelineJobs.status, 'pending')));
return rows.length;
}
// Oldest queued job across everything (single-user → global queue). Used to promote the next job.
export async function getOldestPendingJob() {
const rows = await db