forked from pinks/eris
1
0
Fork 0

show worker long names

This commit is contained in:
pinks 2023-09-13 00:53:50 +02:00
parent 7541deb178
commit b818fc9207
4 changed files with 22 additions and 22 deletions

View File

@ -39,8 +39,8 @@ export async function queueCommand(ctx: Grammy.CommandContext<Context>) {
: ["Queue is empty.\n"], : ["Queue is empty.\n"],
"\nActive workers:\n", "\nActive workers:\n",
...ctx.session.global.workers.flatMap((worker) => [ ...ctx.session.global.workers.flatMap((worker) => [
runningWorkers.has(worker.name) ? "✅ " : "☠️ ", runningWorkers.has(worker.id) ? "✅ " : "☠️ ",
fmt`${bold(worker.name)} `, fmt`${bold(worker.name || worker.id)} `,
`(max ${(worker.maxResolution / 1000000).toFixed(1)} Mpx) `, `(max ${(worker.maxResolution / 1000000).toFixed(1)} Mpx) `,
"\n", "\n",
]), ]),

View File

@ -20,9 +20,9 @@ export interface GlobalData {
} }
export interface WorkerData { export interface WorkerData {
name: string; id: string;
name?: string;
api: SdApi; api: SdApi;
auth?: string;
maxResolution: number; maxResolution: number;
} }
@ -52,7 +52,7 @@ const getDefaultGlobalData = (): GlobalData => ({
}, },
workers: [ workers: [
{ {
name: "local", id: "local",
api: { url: Deno.env.get("SD_API_URL") ?? "http://127.0.0.1:7860/" }, api: { url: Deno.env.get("SD_API_URL") ?? "http://127.0.0.1:7860/" },
maxResolution: 1024 * 1024, maxResolution: 1024 * 1024,
}, },

View File

@ -15,13 +15,13 @@ export async function pingWorkers(): Promise<never> {
const config = await getGlobalSession(); const config = await getGlobalSession();
for (const worker of config.workers) { for (const worker of config.workers) {
const status = await sdGetConfig(worker.api).catch(() => null); const status = await sdGetConfig(worker.api).catch(() => null);
const wasRunning = runningWorkers.has(worker.name); const wasRunning = runningWorkers.has(worker.id);
if (status) { if (status) {
runningWorkers.add(worker.name); runningWorkers.add(worker.id);
if (!wasRunning) logger().info(`Worker ${worker.name} is online`); if (!wasRunning) logger().info(`Worker ${worker.id} is online`);
} else { } else {
runningWorkers.delete(worker.name); runningWorkers.delete(worker.id);
if (wasRunning) logger().warning(`Worker ${worker.name} went offline`); if (wasRunning) logger().warning(`Worker ${worker.id} went offline`);
} }
} }
await Async.delay(60 * 1000); await Async.delay(60 * 1000);

View File

@ -34,8 +34,8 @@ export async function processJobs(): Promise<never> {
// find a worker to handle the job // find a worker to handle the job
const config = await getGlobalSession(); const config = await getGlobalSession();
const worker = config.workers?.find((worker) => const worker = config.workers?.find((worker) =>
runningWorkers.has(worker.name) && runningWorkers.has(worker.id) &&
!busyWorkers.has(worker.name) !busyWorkers.has(worker.id)
); );
if (!worker) continue; if (!worker) continue;
@ -45,16 +45,16 @@ export async function processJobs(): Promise<never> {
status: { status: {
type: "processing", type: "processing",
progress: 0, progress: 0,
worker: worker.name, worker: worker.id,
updatedDate: new Date(), updatedDate: new Date(),
message: job.value.status.type !== "done" ? job.value.status.message : undefined, message: job.value.status.type !== "done" ? job.value.status.message : undefined,
}, },
})); }));
busyWorkers.add(worker.name); busyWorkers.add(worker.id);
processJob(job, worker, config) processJob(job, worker, config)
.catch(async (err) => { .catch(async (err) => {
logger().error( 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) { if (err instanceof Grammy.GrammyError || err instanceof SdApiError) {
await bot.api.sendMessage( await bot.api.sendMessage(
@ -72,9 +72,9 @@ export async function processJobs(): Promise<never> {
err.statusCode === 401 err.statusCode === 401
) )
) { ) {
runningWorkers.delete(worker.name); runningWorkers.delete(worker.id);
logger().warning( 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); await job.delete().catch(() => undefined);
@ -82,7 +82,7 @@ export async function processJobs(): Promise<never> {
await jobStore.create(job.value); await jobStore.create(job.value);
} }
}) })
.finally(() => busyWorkers.delete(worker.name)); .finally(() => busyWorkers.delete(worker.id));
} catch (err) { } catch (err) {
logger().warning(`Processing jobs failed: ${err}`); logger().warning(`Processing jobs failed: ${err}`);
} }
@ -91,7 +91,7 @@ export async function processJobs(): Promise<never> {
async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config: GlobalData) { async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config: GlobalData) {
logger().debug( logger().debug(
`Job started for ${formatUserChat(job.value)} using ${worker.name}`, `Job started for ${formatUserChat(job.value)} using ${worker.id}`,
); );
const startDate = new Date(); const startDate = new Date();
@ -177,7 +177,7 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
status: { status: {
type: "processing", type: "processing",
progress: progress.progress, progress: progress.progress,
worker: worker.name, worker: worker.id,
updatedDate: new Date(), updatedDate: new Date(),
message: value.status.type !== "done" ? value.status.message : undefined, message: value.status.type !== "done" ? value.status.message : undefined,
}, },
@ -237,7 +237,7 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
fmt`${bold("CFG scale:")} ${response.info.cfg_scale}, `, fmt`${bold("CFG scale:")} ${response.info.cfg_scale}, `,
fmt`${bold("Seed:")} ${response.info.seed}, `, fmt`${bold("Seed:")} ${response.info.seed}, `,
fmt`${bold("Size")}: ${response.info.width}x${response.info.height}, `, 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 })}`, fmt`${bold("Time taken")}: ${FmtDuration.format(jobDurationMs, { ignoreZero: true })}`,
] ]
: [], : [],
@ -313,7 +313,7 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
})); }));
logger().debug( 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` : "" sendMediaAttempt > 1 ? ` after ${sendMediaAttempt} attempts` : ""
}`, }`,
); );