From 13d5a7ca013dacd7d7b7b04f4454ff63bb56c60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Mon, 30 Sep 2024 17:00:32 -0300 Subject: [PATCH] formatting --- src/server/api/routers/job.ts | 4 --- src/server/api/routers/ssh.ts | 1 - src/server/api/trpc.ts | 6 +++- src/server/ssh/sesh.ts | 62 +++++++++++++++++------------------ 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/server/api/routers/job.ts b/src/server/api/routers/job.ts index 9e0f8b1..0dc9828 100644 --- a/src/server/api/routers/job.ts +++ b/src/server/api/routers/job.ts @@ -98,7 +98,6 @@ export const jobRouter = createTRPCRouter({ const command = `sacct --job ${jobId}.batch --format=State --parsable2`; const { stdout, stderr } = await connection.execCommand(command); - if (stderr) { throw new Error(stderr); } @@ -132,7 +131,6 @@ export const jobRouter = createTRPCRouter({ const command = `scancel ${jobId}`; const { stderr } = await connection.execCommand(command); - if (stderr) { throw new Error(stderr); } @@ -153,8 +151,6 @@ export const jobRouter = createTRPCRouter({ const command = `sacct --format="State,Submit,Start,End,Elapsed,Partition,NodeList,AllocGRES,NCPUS,Reason,ExitCode" --parsable2 --job ${jobId} --noheader`; const { stdout, stderr } = await connection.execCommand(command); - - if (stderr) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", diff --git a/src/server/api/routers/ssh.ts b/src/server/api/routers/ssh.ts index 8b03b50..992ffa6 100644 --- a/src/server/api/routers/ssh.ts +++ b/src/server/api/routers/ssh.ts @@ -17,7 +17,6 @@ export const sshRouter = createTRPCRouter({ const command = `ls -pm --group-directories-first ${input.path}`; const { stdout, stderr } = await connection.execCommand(command); - if (stderr) { const error = z .object({ diff --git a/src/server/api/trpc.ts b/src/server/api/trpc.ts index 1a0f599..61d44a7 100644 --- a/src/server/api/trpc.ts +++ b/src/server/api/trpc.ts @@ -155,7 +155,11 @@ export const protectedProcedureWithCredentials = t.procedure.use( const res = await next({ ctx: { // infers the `session` as non-nullable - session: { ...ctx.session, credentials: { name: username, keys }, connection }, + session: { + ...ctx.session, + credentials: { name: username, keys }, + connection, + }, }, }); diff --git a/src/server/ssh/sesh.ts b/src/server/ssh/sesh.ts index cd3dc38..6de74dd 100644 --- a/src/server/ssh/sesh.ts +++ b/src/server/ssh/sesh.ts @@ -1,33 +1,33 @@ -import type { NodeSSH } from "node-ssh" +import type { NodeSSH } from "node-ssh"; // a storage-unbounded ttl cache that is not an lru-cache export const cache = { - data: new Map(), - timers: new Map>(), - set: (k: PropertyKey, v: NodeSSH, ttl: number) => { - if (cache.timers.has(k)) { - clearTimeout(cache.timers.get(k)) - } - cache.timers.set( - k, - setTimeout(() => cache.delete(k), ttl) - ) - cache.data.set(k, v) - }, - get: (k: PropertyKey) => cache.data.get(k), - has: (k: PropertyKey) => cache.data.has(k), - delete: (k: PropertyKey) => { - if (cache.timers.has(k)) { - clearTimeout(cache.timers.get(k)) - } - cache.timers.delete(k) - cache.data.get(k)?.dispose() - return cache.data.delete(k) - }, - clear: () => { - cache.data.clear() - for (const v of cache.timers.values()) { - clearTimeout(v) - } - cache.timers.clear() - }, -} \ No newline at end of file + data: new Map(), + timers: new Map>(), + set: (k: PropertyKey, v: NodeSSH, ttl: number) => { + if (cache.timers.has(k)) { + clearTimeout(cache.timers.get(k)); + } + cache.timers.set( + k, + setTimeout(() => cache.delete(k), ttl), + ); + cache.data.set(k, v); + }, + get: (k: PropertyKey) => cache.data.get(k), + has: (k: PropertyKey) => cache.data.has(k), + delete: (k: PropertyKey) => { + if (cache.timers.has(k)) { + clearTimeout(cache.timers.get(k)); + } + cache.timers.delete(k); + cache.data.get(k)?.dispose(); + return cache.data.delete(k); + }, + clear: () => { + cache.data.clear(); + for (const v of cache.timers.values()) { + clearTimeout(v); + } + cache.timers.clear(); + }, +};