From 149037cf7d02f3955a70c9c89c127f850f9edd1c Mon Sep 17 00:00:00 2001 From: orosmatthew Date: Tue, 9 May 2023 16:51:43 -0400 Subject: [PATCH] [sandbox] Catch run errors and fetch more often --- sandbox/src/index.ts | 21 +++++++++++++-------- sandbox/src/run/java.ts | 3 --- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sandbox/src/index.ts b/sandbox/src/index.ts index 0327f42..a35d865 100644 --- a/sandbox/src/index.ts +++ b/sandbox/src/index.ts @@ -65,13 +65,18 @@ async function cloneAndRun(submissionData: SubmissionGetData) { ); await git.checkout(submissionData.submission.commitHash); const problemName = submissionData.submission.problem.pascalName; - const output = await runJava( - javaBinPath, - buildDir, - join(repoDir, problemName, problemName + '.java'), - problemName, - submissionData.submission.problem.realInput - ); + let output: string; + try { + output = await runJava( + javaBinPath, + buildDir, + join(repoDir, problemName, problemName + '.java'), + problemName, + submissionData.submission.problem.realInput + ); + } catch (error) { + output = `[An error occurred while running]\n${error}`; + } const res = await fetch(urlJoin(adminUrl, 'api/submission'), { method: 'POST', @@ -128,7 +133,7 @@ async function loop() { async function run() { while (true) { await loop(); - await new Promise((resolve) => setTimeout(resolve, 15000)); + await new Promise((resolve) => setTimeout(resolve, 10000)); } } diff --git a/sandbox/src/run/java.ts b/sandbox/src/run/java.ts index c9ab573..b3399b3 100644 --- a/sandbox/src/run/java.ts +++ b/sandbox/src/run/java.ts @@ -1,8 +1,5 @@ -import fs from 'fs-extra'; import { join } from 'path'; -import os from 'os'; import { exec, spawn } from 'child_process'; -import { error } from 'console'; import util from 'util'; const execPromise = util.promisify(exec);