18 lines
697 B
TypeScript
18 lines
697 B
TypeScript
import { hasActivePromptJobs } from '~/server/utils/promptComfy'
|
|
import { listJobs } from '~/server/utils/jobs'
|
|
import { registerSharedGpuWork, maintainSharedGpu } from '~/server/utils/sharedGpu'
|
|
|
|
export default defineNitroPlugin((nitro) => {
|
|
registerSharedGpuWork(() => hasActivePromptJobs() || listJobs().some(job =>
|
|
job.saving || job.library?.chainContinuing || ['queued', 'uploading', 'running'].includes(job.status)
|
|
))
|
|
let running = false
|
|
const timer = setInterval(async () => {
|
|
if (running) return
|
|
running = true
|
|
try { await maintainSharedGpu() } finally { running = false }
|
|
}, 10_000)
|
|
timer.unref()
|
|
nitro.hooks.hook('close', () => { clearInterval(timer) })
|
|
})
|