From f4036a93ec48dd39a917ea6b7f20809fba33e1f1 Mon Sep 17 00:00:00 2001 From: Sidney Anderson Date: Tue, 26 May 2026 07:22:30 -0600 Subject: [PATCH] fix: restart queue when a job is queued MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the worker queue drains, it sets is_running=false on the Queue record. If a new job is then queued, the worker's loop skips it entirely because is_running=false — the job sits frozen until the user manually starts the queue. Fix: always set is_running=true on the queue when a job is queued, mirroring what the /api/queue/[queueID]/start route already does. Also fixes the create-path which was creating the queue with is_running=false, meaning a brand-new queue would also never start. --- ui/src/app/api/jobs/[jobID]/start/route.ts | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/ui/src/app/api/jobs/[jobID]/start/route.ts b/ui/src/app/api/jobs/[jobID]/start/route.ts index e69de29b..52704335 100644 --- a/ui/src/app/api/jobs/[jobID]/start/route.ts +++ b/ui/src/app/api/jobs/[jobID]/start/route.ts @@ -0,0 +1,65 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +export async function GET(request: NextRequest, { params }: { params: { jobID: string } }) { + const { jobID } = await params; + + const job = await prisma.job.findUnique({ + where: { id: jobID }, + }); + + if (!job) { + return NextResponse.json({ error: 'Job not found' }, { status: 404 }); + } + + // get highest queue position + const highestQueuePosition = await prisma.job.aggregate({ + _max: { + queue_position: true, + }, + }); + const newQueuePosition = (highestQueuePosition._max.queue_position || 0) + 1000; + + await prisma.job.update({ + where: { id: jobID }, + data: { queue_position: newQueuePosition }, + }); + + // make sure the queue exists and is running + const queue = await prisma.queue.findFirst({ + where: { + gpu_ids: job.gpu_ids, + }, + }); + + // if queue doesn't exist, create it and start it + if (!queue) { + await prisma.queue.create({ + data: { + gpu_ids: job.gpu_ids, + is_running: true, + }, + }); + } else { + // ensure the queue is running so the worker picks up the new job + await prisma.queue.update({ + where: { id: queue.id }, + data: { is_running: true }, + }); + } + + await prisma.job.update({ + where: { id: jobID }, + data: { + status: 'queued', + stop: false, + return_to_queue: false, + info: 'Job queued', + }, + }); + + // Return the response immediately + return NextResponse.json(job); +}