|
1 |
| -import { Computed, Context, Dict, h, Logger, omit, Quester, Session, SessionError, trimSlash } from 'koishi' |
| 1 | +import { Computed, Context, Dict, h, Logger, omit, Quester, Session, SessionError, sleep, trimSlash } from 'koishi' |
2 | 2 | import { Config, modelMap, models, orientMap, parseInput, sampler, upscalers, scheduler } from './config'
|
3 | 3 | import { ImageData, StableDiffusionWebUI } from './types'
|
4 | 4 | import { closestMultiple, download, forceDataPrefix, getImageSize, login, NetworkError, project, resizeInput, Size } from './utils'
|
@@ -285,6 +285,12 @@ export function apply(ctx: Context, config: Config) {
|
285 | 285 | session.send(globalTasks.size
|
286 | 286 | ? session.text('.pending', [globalTasks.size])
|
287 | 287 | : session.text('.waiting'))
|
| 288 | + |
| 289 | + if (config.globalConcurrency) { |
| 290 | + while (globalTasks.size >= config.globalConcurrency) { |
| 291 | + await sleep(100) |
| 292 | + } |
| 293 | + } |
288 | 294 |
|
289 | 295 | container.forEach((id) => globalTasks.add(id))
|
290 | 296 | const cleanUp = (id: string) => {
|
@@ -428,7 +434,6 @@ export function apply(ctx: Context, config: Config) {
|
428 | 434 | const uuid = res.data.id
|
429 | 435 |
|
430 | 436 | const check = () => ctx.http.get(trimSlash(config.endpoint) + '/api/v2/generate/check/' + uuid).then((res) => res.done)
|
431 |
| - const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) |
432 | 437 | while (await check() === false) {
|
433 | 438 | await sleep(config.pollInterval)
|
434 | 439 | }
|
|
0 commit comments