diff --git a/apps/worker-compiler/src/index.ts b/apps/worker-compiler/src/index.ts index 463645c..90f7a5b 100644 --- a/apps/worker-compiler/src/index.ts +++ b/apps/worker-compiler/src/index.ts @@ -164,24 +164,9 @@ async function runCommand(command: string, code: string, language: string, expec const startTime = process.hrtime(); const createdAt = new Date().toISOString(); - const timeout = setTimeout(() => { - reject({ - stderr: 'Error: Time limit exceeded', - timeTaken: parseFloat((process.hrtime(startTime)[0] + process.hrtime(startTime)[1] / 1e9).toFixed(3)), - memoryUsage: Math.floor(process.memoryUsage().heapUsed / 1024), - created_at: createdAt, - finished_at: new Date().toISOString(), - source_code: code, - language_id: language, - compile_output: '', - exit_code: null, - status_id: 7 // Status ID for time limit exceeded - }); - }, 5000); // Set time limit to 5 seconds - exec(command, (error, stdout, stderr) => { + exec(command, { timeout: 5000 }, (error, stdout, stderr) => { - clearTimeout(timeout); const endTime = process.hrtime(startTime); const timeTaken = parseFloat((endTime[0] + endTime[1] / 1e9).toFixed(3)); // Convert to seconds and milliseconds till 3 digits const finishedAt = new Date().toISOString();