Skip to content

Commit 640d501

Browse files
committed
initial commit
Signed-off-by: Tathagat Thapliyal <tathagat.thapliyal@gmail.com>
1 parent 81f9071 commit 640d501

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/tasks/submission.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import config = require('../../config.js')
2+
import { cat, exec, mkdir, rm } from 'shelljs'
3+
import { SubmissionJob, SubmissionResult } from '../types/job'
4+
import * as path from 'path'
5+
import * as fs from 'fs'
6+
7+
rm('-rf', config.RUNBOX.DIR)
8+
mkdir('-p', config.RUNBOX.DIR)
9+
10+
async function execSubmission(job: SubmissionJob): Promise<SubmissionResult> {
11+
let currentJobDir = path.join(config.RUNBOX.DIR, job.id.toString())
12+
mkdir('-p', currentJobDir)
13+
const LANG_CONFIG = config.LANGS[job.lang]
14+
15+
fs.writeFileSync(path.join(currentJobDir, LANG_CONFIG.SOURCE_FILE),
16+
(new Buffer(job.source, 'base64')).toString('ascii'))
17+
18+
exec(`docker run \\
19+
--cpus="${LANG_CONFIG.CPU_SHARE}" \\
20+
--memory="${LANG_CONFIG.MEM_LIMIT}" \\
21+
--ulimit nofile=64:64 \\
22+
--rm \\
23+
--read-only \\
24+
-v "${currentJobDir}":/usr/src/runbox \\
25+
-w /usr/src/runbox \\
26+
codingblocks/judge-worker-${job.lang} \\
27+
/bin/judge.sh -t ${job.timelimit || 5}
28+
`)
29+
30+
const stdout = exec(`
31+
head -c 65536 ${path.join(currentJobDir, 'run.stdout')}
32+
`)
33+
34+
// Check for compile_stderr if can't find a stdout file ; stdout can be ''
35+
const compile_stderr = cat(path.join(currentJobDir, 'compile.stderr')).toString()
36+
const runguard_stderr = cat(path.join(currentJobDir, 'runguard.stderr')).toString()
37+
let stderr = runguard_stderr || compile_stderr || cat((path.join(currentJobDir, 'run.stderr')).toString())
38+
39+
rm('-rf', currentJobDir)
40+
41+
}
42+
43+
return {
44+
45+
}
46+
47+
export {
48+
execSubmission
49+
}

src/types/job.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ export interface RunResult {
1515
}
1616

1717
export interface SubmissionJob {
18-
id: number,
18+
id: number
1919
source: string,
2020
lang: string,
21-
testcases: [{input: string, output: string}]
22-
getstdout: boolean,
21+
timelimit?: number,
22+
testcases: [{ id: number, input: string, output: string }],
2323
}
2424

2525
export interface SubmissionResult {
2626
id: number,
27-
results: [{resultcode: number, stdout?: string, stderr?: string}]
27+
stderr: string,
28+
testcases: [{ id: number, sscore: number, time: string, result: string }]
2829
}

0 commit comments

Comments
 (0)