Coordinate shared GPU access across studio instances
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { comfyInputFilename } from '~/server/utils/comfy'
|
||||
import { assertSharedGpu, sharedGpuHeaders, sharedGpuConfigured } from '~/server/utils/sharedGpu'
|
||||
import { comfyInputFilename, getComfyHost } from '~/server/utils/comfy'
|
||||
import { getSidecarImageHost } from '~/server/utils/imageComfy'
|
||||
import { ensureSidecarReady } from '~/server/utils/imageComfyLifecycle'
|
||||
import { buildVisionPromptWorkflow } from '~/server/utils/promptWorkflow'
|
||||
@@ -19,6 +20,7 @@ const jobs = new Map<string, PromptJob>()
|
||||
const MAX_JOBS = 20
|
||||
|
||||
export function getPromptComfyHost() {
|
||||
if (sharedGpuConfigured()) return getComfyHost()
|
||||
return getSidecarImageHost()
|
||||
}
|
||||
|
||||
@@ -31,6 +33,12 @@ async function promptComfyFetch(path: string, init?: RequestInit) {
|
||||
if (!host) {
|
||||
throw createError({ statusCode: 503, statusMessage: 'Qwen VL is not configured. Set COMFY_HOST or IMAGE_COMFY_HOST to Beast.' })
|
||||
}
|
||||
if (init?.method && !['GET', 'HEAD'].includes(init.method.toUpperCase())) {
|
||||
await assertSharedGpu()
|
||||
const headers = new Headers(init.headers)
|
||||
for (const [key, value] of Object.entries(sharedGpuHeaders())) headers.set(key, value)
|
||||
init = { ...init, headers }
|
||||
}
|
||||
try {
|
||||
return await fetch(`${host}${path}`, init)
|
||||
} catch (error) {
|
||||
@@ -260,3 +268,7 @@ export function failPromptJob(job: PromptJob, error: unknown) {
|
||||
job.error = err.statusMessage || err.message || 'Prompt recommend failed'
|
||||
job.message = job.error
|
||||
}
|
||||
|
||||
export function hasActivePromptJobs() {
|
||||
return [...jobs.values()].some(job => job.status === 'queued' || job.status === 'running')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user