diff --git a/bot/queueCommand.ts b/bot/queueCommand.ts index 31d2f41..de6c446 100644 --- a/bot/queueCommand.ts +++ b/bot/queueCommand.ts @@ -39,8 +39,8 @@ export async function queueCommand(ctx: Grammy.CommandContext) { : ["Queue is empty.\n"], "\nActive workers:\n", ...ctx.session.global.workers.flatMap((worker) => [ - runningWorkers.has(worker.name) ? "✅ " : "☠️ ", - fmt`${bold(worker.name)} `, + runningWorkers.has(worker.id) ? "✅ " : "☠️ ", + fmt`${bold(worker.name || worker.id)} `, `(max ${(worker.maxResolution / 1000000).toFixed(1)} Mpx) `, "\n", ]), diff --git a/bot/session.ts b/bot/session.ts index 62c50be..0a769ef 100644 --- a/bot/session.ts +++ b/bot/session.ts @@ -20,9 +20,9 @@ export interface GlobalData { } export interface WorkerData { - name: string; + id: string; + name?: string; api: SdApi; - auth?: string; maxResolution: number; } @@ -52,7 +52,7 @@ const getDefaultGlobalData = (): GlobalData => ({ }, workers: [ { - name: "local", + id: "local", api: { url: Deno.env.get("SD_API_URL") ?? "http://127.0.0.1:7860/" }, maxResolution: 1024 * 1024, }, diff --git a/tasks/pingWorkers.ts b/tasks/pingWorkers.ts index cee5e6f..ae445c5 100644 --- a/tasks/pingWorkers.ts +++ b/tasks/pingWorkers.ts @@ -15,13 +15,13 @@ export async function pingWorkers(): Promise { const config = await getGlobalSession(); for (const worker of config.workers) { const status = await sdGetConfig(worker.api).catch(() => null); - const wasRunning = runningWorkers.has(worker.name); + const wasRunning = runningWorkers.has(worker.id); if (status) { - runningWorkers.add(worker.name); - if (!wasRunning) logger().info(`Worker ${worker.name} is online`); + runningWorkers.add(worker.id); + if (!wasRunning) logger().info(`Worker ${worker.id} is online`); } else { - runningWorkers.delete(worker.name); - if (wasRunning) logger().warning(`Worker ${worker.name} went offline`); + runningWorkers.delete(worker.id); + if (wasRunning) logger().warning(`Worker ${worker.id} went offline`); } } await Async.delay(60 * 1000); diff --git a/tasks/processJobs.ts b/tasks/processJobs.ts index d64a7b4..939cbc4 100644 --- a/tasks/processJobs.ts +++ b/tasks/processJobs.ts @@ -34,8 +34,8 @@ export async function processJobs(): Promise { // find a worker to handle the job const config = await getGlobalSession(); const worker = config.workers?.find((worker) => - runningWorkers.has(worker.name) && - !busyWorkers.has(worker.name) + runningWorkers.has(worker.id) && + !busyWorkers.has(worker.id) ); if (!worker) continue; @@ -45,16 +45,16 @@ export async function processJobs(): Promise { status: { type: "processing", progress: 0, - worker: worker.name, + worker: worker.id, updatedDate: new Date(), message: job.value.status.type !== "done" ? job.value.status.message : undefined, }, })); - busyWorkers.add(worker.name); + busyWorkers.add(worker.id); processJob(job, worker, config) .catch(async (err) => { logger().error( - `Job failed for ${formatUserChat(job.value)} via ${worker.name}: ${err}`, + `Job failed for ${formatUserChat(job.value)} via ${worker.id}: ${err}`, ); if (err instanceof Grammy.GrammyError || err instanceof SdApiError) { await bot.api.sendMessage( @@ -72,9 +72,9 @@ export async function processJobs(): Promise { err.statusCode === 401 ) ) { - runningWorkers.delete(worker.name); + runningWorkers.delete(worker.id); logger().warning( - `Worker ${worker.name} was marked as offline because of network error`, + `Worker ${worker.id} was marked as offline because of network error`, ); } await job.delete().catch(() => undefined); @@ -82,7 +82,7 @@ export async function processJobs(): Promise { await jobStore.create(job.value); } }) - .finally(() => busyWorkers.delete(worker.name)); + .finally(() => busyWorkers.delete(worker.id)); } catch (err) { logger().warning(`Processing jobs failed: ${err}`); } @@ -91,7 +91,7 @@ export async function processJobs(): Promise { async function processJob(job: IKV.Model, worker: WorkerData, config: GlobalData) { logger().debug( - `Job started for ${formatUserChat(job.value)} using ${worker.name}`, + `Job started for ${formatUserChat(job.value)} using ${worker.id}`, ); const startDate = new Date(); @@ -177,7 +177,7 @@ async function processJob(job: IKV.Model, worker: WorkerData, config: status: { type: "processing", progress: progress.progress, - worker: worker.name, + worker: worker.id, updatedDate: new Date(), message: value.status.type !== "done" ? value.status.message : undefined, }, @@ -237,7 +237,7 @@ async function processJob(job: IKV.Model, worker: WorkerData, config: fmt`${bold("CFG scale:")} ${response.info.cfg_scale}, `, fmt`${bold("Seed:")} ${response.info.seed}, `, fmt`${bold("Size")}: ${response.info.width}x${response.info.height}, `, - fmt`${bold("Worker")}: ${worker.name}, `, + fmt`${bold("Worker")}: ${worker.id}, `, fmt`${bold("Time taken")}: ${FmtDuration.format(jobDurationMs, { ignoreZero: true })}`, ] : [], @@ -313,7 +313,7 @@ async function processJob(job: IKV.Model, worker: WorkerData, config: })); logger().debug( - `Job finished for ${formatUserChat(job.value)} using ${worker.name}${ + `Job finished for ${formatUserChat(job.value)} using ${worker.id}${ sendMediaAttempt > 1 ? ` after ${sendMediaAttempt} attempts` : "" }`, );