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"],
"\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",
]),

View File

@ -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,
},

View File

@ -15,13 +15,13 @@ export async function pingWorkers(): Promise<never> {
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);

View File

@ -34,8 +34,8 @@ export async function processJobs(): Promise<never> {
// 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<never> {
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<never> {
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<never> {
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<never> {
async function processJob(job: IKV.Model<JobSchema>, 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<JobSchema>, 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<JobSchema>, 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<JobSchema>, 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` : ""
}`,
);