import { listJobs } from '~/server/utils/jobs' import { listOwnersWithStudioQueues, listStudioJobs } from '~/server/utils/studioQueue' import { requestComfySleep } from '~/server/utils/comfyLifecycle' export default defineEventHandler(async () => { const live = listJobs().filter(job => job.status === 'queued' || job.status === 'uploading' || job.status === 'running') if (live.length) { throw createError({ statusCode: 409, statusMessage: 'A job is still running. Cancel it first, then sleep the GPU.' }) } for (const owner of listOwnersWithStudioQueues()) { if (listStudioJobs(owner).some(job => job.status === 'running')) { throw createError({ statusCode: 409, statusMessage: 'A job is still running. Cancel it first, then sleep the GPU.' }) } } return await requestComfySleep() })