Browse Source

Push run task to rabbitmq at web side

pull/6/head
hewenyang 7 years ago
parent
commit
a8d7d86e01
  1. 3
      config-example.json
  2. 41
      libs/judger.js
  3. 1316
      package-lock.json
  4. 3
      package.json

3
config-example.json

@ -167,6 +167,7 @@
],
"session_secret": "233",
"judge_server_addr": "http://127.0.0.1:5284",
"rabbitMQ": "amqp://localhost/",
"judge_token": "233",
"email_jwt_secret": "test"
}
}

41
libs/judger.js

@ -2,7 +2,33 @@ const enums = require('./enums'),
rp = require('request-promise'),
url = require('url');
const amqp = require('amqplib');
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) {
let type, param, extraFile = null;
switch (problem.type) {
@ -44,13 +70,8 @@ module.exports.judge = async function (judge_state, problem, priority) {
extraFileLocation: extraFile
};
await rp(url.resolve(syzoj.config.judge_server_addr, "/daemon/task"), {
method: 'PUT',
body: req,
headers: {
Token: syzoj.config.judge_token
},
json: true,
simple: true
});
}
// TODO: parse extraFileLocation
publicChannel.sendToQueue('judge', msgPack.encode({ content: req.content, extraData: null }), { priority: priority });
}
connect();

1316
package-lock.json generated

File diff suppressed because it is too large Load Diff

3
package.json

@ -23,6 +23,7 @@
},
"homepage": "https://github.com/syzoj/syzoj#readme",
"dependencies": {
"amqplib": "^0.5.2",
"ansi-to-html": "^0.4.2",
"async-lock": "^0.3.9",
"body-parser": "^1.15.2",
@ -42,6 +43,7 @@
"jsonwebtoken": "^7.4.3",
"moemark-renderer": "^1.2.6",
"moment": "^2.15.0",
"msgpack-lite": "^0.1.26",
"multer": "^1.2.0",
"mysql": "^2.11.1",
"node-7z": "^0.4.0",
@ -57,6 +59,7 @@
"syzoj-divine": "^1.0.2",
"tmp-promise": "^1.0.3",
"waliyun": "^3.1.1",
"winston": "^2.3.1",
"xss": "^0.3.3"
}
}

Loading…
Cancel
Save