mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
refactor(judge): fetch timeLimit and memoryLimit from Problem instead of DockerConfig
This commit is contained in:
parent
82428bbd09
commit
895c3f779d
@ -65,6 +65,7 @@ function createTarStream(file: string, value: string) {
|
|||||||
export async function judge(
|
export async function judge(
|
||||||
language: EditorLanguage,
|
language: EditorLanguage,
|
||||||
value: string,
|
value: string,
|
||||||
|
problemId: string,
|
||||||
): Promise<JudgeResult> {
|
): Promise<JudgeResult> {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session) redirect("/sign-in");
|
if (!session) redirect("/sign-in");
|
||||||
@ -89,12 +90,28 @@ export async function judge(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const problem = await prisma.problem.findUnique({
|
||||||
|
where: { id: problemId },
|
||||||
|
select: {
|
||||||
|
timeLimit: true,
|
||||||
|
memoryLimit: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!problem) {
|
||||||
|
return {
|
||||||
|
id: uuid(),
|
||||||
|
output: "Problem not found.",
|
||||||
|
exitCode: ExitCode.SE,
|
||||||
|
executionTime: null,
|
||||||
|
memoryUsage: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
image,
|
image,
|
||||||
tag,
|
tag,
|
||||||
workingDir,
|
workingDir,
|
||||||
memoryLimit,
|
|
||||||
timeLimit,
|
|
||||||
compileOutputLimit,
|
compileOutputLimit,
|
||||||
runOutputLimit,
|
runOutputLimit,
|
||||||
} = config.dockerConfig;
|
} = config.dockerConfig;
|
||||||
@ -103,7 +120,7 @@ export async function judge(
|
|||||||
|
|
||||||
// Prepare the environment and create a container
|
// Prepare the environment and create a container
|
||||||
await prepareEnvironment(image, tag);
|
await prepareEnvironment(image, tag);
|
||||||
container = await createContainer(image, tag, workingDir, memoryLimit);
|
container = await createContainer(image, tag, workingDir, problem.memoryLimit);
|
||||||
|
|
||||||
// Upload code to the container
|
// Upload code to the container
|
||||||
const tarStream = createTarStream(file, value);
|
const tarStream = createTarStream(file, value);
|
||||||
@ -116,7 +133,7 @@ export async function judge(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the code
|
// Run the code
|
||||||
const runResult = await run(container, fileName, timeLimit, runOutputLimit);
|
const runResult = await run(container, fileName, problem.timeLimit, runOutputLimit);
|
||||||
return runResult;
|
return runResult;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -22,7 +22,7 @@ export function RunCode({
|
|||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: RunCodeProps) {
|
}: RunCodeProps) {
|
||||||
const { currentLang, editor } = useProblem();
|
const { currentLang, editor, problemId } = useProblem();
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
const handleJudge = async () => {
|
const handleJudge = async () => {
|
||||||
@ -32,7 +32,7 @@ export function RunCode({
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await judge(currentLang, code);
|
const result = await judge(currentLang, code, problemId);
|
||||||
showExitCodeToast({ exitCode: result.exitCode });
|
showExitCodeToast({ exitCode: result.exitCode });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error occurred while judging the code:");
|
console.error("Error occurred while judging the code:");
|
||||||
|
Loading…
Reference in New Issue
Block a user