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:
@@ -7,6 +7,7 @@ import {
|
||||
updatePipelineJob,
|
||||
getPipelineJobsForUser,
|
||||
getOldestPendingJob,
|
||||
countPendingJobs,
|
||||
markInterruptedJobs,
|
||||
getUserById,
|
||||
} from 'officerdb';
|
||||
@@ -306,6 +307,21 @@ export async function getJobsForUser(userId: number) {
|
||||
}));
|
||||
}
|
||||
|
||||
// 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 }> {
|
||||
let running = 0;
|
||||
let runningJobId: string | null = null;
|
||||
for (const [id, job] of liveJobs) {
|
||||
if (job.userId === userId) {
|
||||
running++;
|
||||
if (!runningJobId) runningJobId = id;
|
||||
}
|
||||
}
|
||||
const queued = await countPendingJobs(userId);
|
||||
return { running, runningJobId, queued };
|
||||
}
|
||||
|
||||
export async function getJob(jobId: string) {
|
||||
const job = await getPipelineJob(jobId);
|
||||
if (!job) return null;
|
||||
|
||||
@@ -65,6 +65,13 @@ pipelineJobsRouter.post('/', async (c) => {
|
||||
return c.json({ jobId, status });
|
||||
});
|
||||
|
||||
// GET /counts — header-badge summary { running, runningJobId, queued }. Before /:id so it isn't
|
||||
// captured as an id.
|
||||
pipelineJobsRouter.get('/counts', async (c) => {
|
||||
const user = c.get('user');
|
||||
return c.json(await jobManager.getCounts(user.id));
|
||||
});
|
||||
|
||||
// GET /:id/log?offset= — tail the persisted output log (script jobs). Returns text from `offset`.
|
||||
pipelineJobsRouter.get('/:id/log', async (c) => {
|
||||
const user = c.get('user');
|
||||
|
||||
Reference in New Issue
Block a user