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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user