Skip to content

Commit 5189d2f

Browse files
committed
add error queue and download testcases in result hook
1 parent ab79a08 commit 5189d2f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/taskmaster.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Raven.config(config.SENTRY.DSN, {
1515
}).install()
1616
// =============== Setup Raven
1717

18-
let jobQ = 'job_queue'
19-
let successQ = 'success_queue'
18+
const jobQ = 'job_queue'
19+
const successQ = 'success_queue'
20+
const errorQ = 'error_queue'
2021

2122
mkdir('-p', config.RUNBOX.DIR)
2223

@@ -27,6 +28,7 @@ amqp.connect(`amqp://${config.AMQP.USER}:${config.AMQP.PASS}@${config.AMQP.HOST}
2728

2829
channel.assertQueue(successQ);
2930
channel.assertQueue(jobQ);
31+
channel.assertQueue(errorQ);
3032
channel.consume(jobQ, async (msg) => {
3133
try {
3234
const payload = JSON.parse(msg.content.toString())
@@ -45,11 +47,10 @@ amqp.connect(`amqp://${config.AMQP.USER}:${config.AMQP.PASS}@${config.AMQP.HOST}
4547

4648
const jobResult = await execute(job)
4749

48-
// TODO
49-
channel.sendToQueue(successQ, (new Buffer(JSON.stringify(jobResult))))
50-
50+
channel.sendToQueue(successQ, (new Buffer(JSON.stringify(jobResult))))
5151
} catch (err) {
5252
Raven.captureException(err);
53+
channel.sendToQueue(errorQ, (new Buffer(msg.content)))
5354
}
5455
channel.ack(msg)
5556
})

src/tasks/scenarios/submission.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ class SubmissionScenario extends Scenario {
3131
const testCasesDir = path.join(currentJobDir, 'testcases')
3232
mkdir('-p', testCasesDir)
3333

34-
return Promise.all(job.testcases.map(async testcase => {
34+
return Promise.all(job.testcases.map(testcase => {
3535
const rootDir = path.join(testCasesDir, '' + testcase.id)
3636
mkdir('-p', rootDir)
37-
const input = await download(testcase.input, path.join(rootDir, 'stdin'))
38-
const output = await download(testcase.output, path.join(rootDir, 'stdout'))
37+
return download(testcase.input, path.join(rootDir, 'stdin'))
3938
}))
4039
}
4140

@@ -51,6 +50,11 @@ class SubmissionScenario extends Scenario {
5150
}
5251
}
5352

53+
await Promise.all(job.testcases.map(async testcase => {
54+
const rootDir = path.join(currentJobDir, 'testcases', '' + testcase.id)
55+
return download(testcase.output, path.join(rootDir, 'stdout'))
56+
}))
57+
5458
const testcases = ls(path.join(currentJobDir, 'testcases')).map(testcase => {
5559
const currentTestcasePath = path.join(currentJobDir, 'testcases', testcase)
5660

test/scenarios/submissionScenario.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ describe('Submission Scenario', () => {
4343
const stdin = fs.readFileSync(path.join(currentJobDir, 'testcases', '' + job.testcases[0].id, 'stdin')).toString()
4444
expect(stdin.trim()).to.eq('World')
4545

46-
const stdout = fs.readFileSync(path.join(currentJobDir, 'testcases', '' + job.testcases[0].id, 'stdout')).toString()
47-
expect(stdout.trim()).to.eq('Hello World')
46+
const stdout = () => fs.readFileSync(path.join(currentJobDir, 'testcases', '' + job.testcases[0].id, 'stdout')).toString()
47+
expect(stdout).to.throw()
4848

4949
})
5050
})

0 commit comments

Comments
 (0)