Skip to content

Commit

Permalink
(FORMATTING)
Browse files Browse the repository at this point in the history
  • Loading branch information
matyson committed Oct 1, 2024
1 parent 3fdb727 commit f9248df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 39 deletions.
36 changes: 18 additions & 18 deletions apps/deepsirius-ui/src/lib/schemas/user-partitions.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { z } from "zod";
import { z } from 'zod';

const cpusStateSchema = z.object({
allocated: z.string(),
idle: z.string(),
other: z.string(),
total: z.string(),
allocated: z.string(),
idle: z.string(),
other: z.string(),
total: z.string(),
});

const groupQoSLimitSchema = z.object({
cpu: z.string().optional(),
gpu: z.string().optional(),
mem: z.string().optional(),
cpu: z.string().optional(),
gpu: z.string().optional(),
mem: z.string().optional(),
});

const partitionSchema = z.object({
partitionName: z.string(),
qos: z.string(),
nodeList: z.string(),
cpusState: cpusStateSchema,
gresTotal: z.string(),
gresUsed: z.string(),
groupQoSLimit: groupQoSLimitSchema,
partitionName: z.string(),
qos: z.string(),
nodeList: z.string(),
cpusState: cpusStateSchema,
gresTotal: z.string(),
gresUsed: z.string(),
groupQoSLimit: groupQoSLimitSchema,
});

export const userPartitionsResponseSchema = z.object({
username: z.string(),
partitions: z.array(partitionSchema),
});
username: z.string(),
partitions: z.array(partitionSchema),
});
37 changes: 16 additions & 21 deletions apps/deepsirius-ui/src/server/api/routers/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const reportSacctFormatSchema = z.object({
exitCode: z.string().optional(),
});


export const jobRouter = createTRPCRouter({
checkStatus: protectedSSHProcedure
.input(
Expand Down Expand Up @@ -98,23 +97,23 @@ export const jobRouter = createTRPCRouter({

if (stderr) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
code: 'INTERNAL_SERVER_ERROR',
message: stderr,
});
}

const data = stdout.trim();
if (data.length === 0) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Job data not found",
code: 'NOT_FOUND',
message: 'Job data not found',
});
}

const firstline = data.split("\n")[0];
const firstline = data.split('\n')[0];
if (!firstline) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
code: 'INTERNAL_SERVER_ERROR',
message: `Error parsing job data for jobId ${jobId}`,
});
}
Expand All @@ -131,10 +130,10 @@ export const jobRouter = createTRPCRouter({
nCPUS,
reason,
exitCode,
] = data.split("|");
] = data.split('|');

const report = reportSacctFormatSchema.safeParse({
state: state?.split(" ")[0] ?? state, // the state comes with a suffix that we don't need, so we split it and get the first part
state: state?.split(' ')[0] ?? state, // the state comes with a suffix that we don't need, so we split it and get the first part
submit,
start,
end,
Expand All @@ -149,25 +148,22 @@ export const jobRouter = createTRPCRouter({

if (report.error) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Error parsing job data:" + report.error.message,
code: 'INTERNAL_SERVER_ERROR',
message: 'Error parsing job data:' + report.error.message,
});
}

return {
...report.data
...report.data,
};
}),
userPartitions: protectedSSHProcedure.query(async ({ ctx }) => {
const connection = ctx.connection;

const templatePath = "public/templates/user-partitions.sh";
const scriptTemplate = await fs.readFile(templatePath, "utf-8");
const templatePath = 'public/templates/user-partitions.sh';
const scriptTemplate = await fs.readFile(templatePath, 'utf-8');

const content = scriptTemplate.replace(
"${INPUT_USERNAME}",
ctx.username,
);
const content = scriptTemplate.replace('${INPUT_USERNAME}', ctx.username);

const { stdout, stderr } = await connection.execCommand(content);

Expand All @@ -176,7 +172,7 @@ export const jobRouter = createTRPCRouter({
}

if (stdout.trim().length === 0) {
throw new Error("Empty response from user partitions script.");
throw new Error('Empty response from user partitions script.');
}

const parsed = userPartitionsResponseSchema.safeParse(
Expand All @@ -190,7 +186,7 @@ export const jobRouter = createTRPCRouter({
if (value === null || value === undefined) {
return undefined;
}
if (value === "null") {
if (value === 'null') {
return undefined;
}
const parsed = parseInt(value, 10);
Expand Down Expand Up @@ -231,6 +227,5 @@ export const jobRouter = createTRPCRouter({
});

return { partitions };
})
}),
});

0 comments on commit f9248df

Please sign in to comment.