|
|
@ -2,7 +2,33 @@ const enums = require('./enums'), |
|
|
|
rp = require('request-promise'), |
|
|
|
rp = require('request-promise'), |
|
|
|
url = require('url'); |
|
|
|
url = require('url'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const amqp = require('amqplib'); |
|
|
|
const util = require('util'); |
|
|
|
const util = require('util'); |
|
|
|
|
|
|
|
const winston = require('winston'); |
|
|
|
|
|
|
|
const msgPack = require('msgpack-lite'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let amqpConnection; |
|
|
|
|
|
|
|
let publicChannel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function connect () { |
|
|
|
|
|
|
|
amqpConnection = await amqp.connect(syzoj.config.rabbitMQ); |
|
|
|
|
|
|
|
publicChannel = await amqpConnection.createChannel(); |
|
|
|
|
|
|
|
await publicChannel.assertQueue('judge', { |
|
|
|
|
|
|
|
maxPriority: 5, |
|
|
|
|
|
|
|
durable: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
await publicChannel.assertQueue('result', { |
|
|
|
|
|
|
|
durable: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
await publicChannel.assertExchange('progress', 'fanout', { |
|
|
|
|
|
|
|
durable: false |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
amqpConnection.on('error', (err) => { |
|
|
|
|
|
|
|
winston.error('RabbitMQ connection failure: ${err.toString()}'); |
|
|
|
|
|
|
|
amqpConnection.close(); |
|
|
|
|
|
|
|
process.exit(1); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
module.exports.judge = async function (judge_state, problem, priority) { |
|
|
|
module.exports.judge = async function (judge_state, problem, priority) { |
|
|
|
let type, param, extraFile = null; |
|
|
|
let type, param, extraFile = null; |
|
|
|
switch (problem.type) { |
|
|
|
switch (problem.type) { |
|
|
@ -44,13 +70,8 @@ module.exports.judge = async function (judge_state, problem, priority) { |
|
|
|
extraFileLocation: extraFile |
|
|
|
extraFileLocation: extraFile |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await rp(url.resolve(syzoj.config.judge_server_addr, "/daemon/task"), { |
|
|
|
// TODO: parse extraFileLocation
|
|
|
|
method: 'PUT', |
|
|
|
publicChannel.sendToQueue('judge', msgPack.encode({ content: req.content, extraData: null }), { priority: priority }); |
|
|
|
body: req, |
|
|
|
} |
|
|
|
headers: { |
|
|
|
|
|
|
|
Token: syzoj.config.judge_token |
|
|
|
connect(); |
|
|
|
}, |
|
|
|
|
|
|
|
json: true, |
|
|
|
|
|
|
|
simple: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|