Skip to content

Commit 8457357

Browse files
committed
install and use AdmZip
1 parent b6ce935 commit 8457357

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"typescript": "^3.8.3"
2020
},
2121
"dependencies": {
22+
"adm-zip": "^0.4.14",
2223
"amqplib": "^0.5.2",
2324
"newrelic": "^6.5.0",
2425
"raven": "^2.6.4",

src/tasks/scenarios/project.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,41 @@ import { ProjectResult } from 'types/result'
55
import * as path from 'path'
66
import { Scenario } from 'tasks/scenario'
77
import { download } from 'utils/request'
8+
const AdmZip = require('adm-zip')
89

910
export default class ProjectScenario extends Scenario {
1011
async setup(currentJobDir: string, job: ProjectJob) {
11-
// check this. directory might be wrong
12+
13+
// for testing only, change it to download
14+
var problemZip = new AdmZip('/judge-worker-prabal/current/problem.zip')
15+
var solutionZip = new AdmZip('/judge-worker-prabal/current/solution.zip')
16+
1217
const problemDir = path.join(currentJobDir, 'problem')
1318
mkdir('-p', problemDir)
14-
await download(job.problem, path.join(problemDir, 'problem'))
19+
problemZip.extractAllTo(problemDir, true);
1520

1621
const solutionDir = path.join(currentJobDir, 'solution')
1722
mkdir('-p', solutionDir)
18-
await download(job.source, path.join(solutionDir, 'solution'))
23+
solutionZip.extractAllTo(solutionDir, true);
1924
}
2025

2126
run(currentJobDir: string, job: ProjectJob) {
27+
28+
// LANG_CONFIG is undefined rn
2229
const LANG_CONFIG = config.LANGS[job.lang]
2330
return exec(`docker run \\
24-
--cpus="${LANG_CONFIG.CPU_SHARE}" \\
25-
--memory="${LANG_CONFIG.MEM_LIMIT}" \\
31+
--cpus="1" \\
32+
--memory="100m" \\
2633
--rm \\
2734
-v "${currentJobDir}":/usr/src/runbox \\
2835
-w /usr/src/runbox codingblocks/project-worker-"${job.lang}" \\
29-
/bin/judge.sh -s "${job.submissionDirs}"
36+
/bin/judge.sh -s "${job.submissionDirs}
3037
`);
3138
}
3239

3340
async result(currentJobDir: string, job: ProjectJob): Promise<ProjectResult> {
3441

3542
const result_code = cat(path.join(currentJobDir, 'result.code')).toString()
36-
3743
if (result_code) {
3844
// problem hash and solution hash were not equal. // error
3945
return {
@@ -42,7 +48,7 @@ export default class ProjectScenario extends Scenario {
4248
stdout: '',
4349
code: parseInt(result_code),
4450
time: 1,
45-
score: 0
51+
score: 12
4652
}
4753
}
4854

@@ -52,11 +58,11 @@ export default class ProjectScenario extends Scenario {
5258
if (stderr) {
5359
return {
5460
id: job.id,
55-
stderr: build_stderr,
61+
stderr,
5662
stdout: '',
5763
code: 12123,
5864
time: 1,
59-
score: 0
65+
score: 100
6066
}
6167
}
6268

@@ -68,8 +74,8 @@ export default class ProjectScenario extends Scenario {
6874
stderr: '',
6975
stdout: stdout,
7076
time: 0,
71-
code: 0,
72-
score: 0
77+
code: 10,
78+
score: 100
7379
}
7480
}
7581
}

0 commit comments

Comments
 (0)