diff --git a/app.js b/app.js index fe2b9f8..9af6d40 100644 --- a/app.js +++ b/app.js @@ -39,13 +39,12 @@ global.syzoj = { console.log(obj); }, async run() { - let winstonLib = require('./libs/winston'); - winstonLib.configureWinston(true); - let Express = require('express'); global.app = Express(); syzoj.production = app.get('env') === 'production'; + let winstonLib = require('./libs/winston'); + winstonLib.configureWinston(!syzoj.production); app.server = require('http').createServer(app); app.server.listen(parseInt(syzoj.config.port), syzoj.config.hostname, () => { @@ -86,6 +85,7 @@ global.syzoj = { app.use(csurf({ cookie: true })); await this.connectDatabase(); + await this.lib('judger').connect(); this.loadModules(); }, async connectDatabase() { diff --git a/libs/judgeResult.js b/libs/judgeResult.js index 88959cf..ddd8197 100644 --- a/libs/judgeResult.js +++ b/libs/judgeResult.js @@ -2,37 +2,37 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); const winston = require("winston"); -const interfaces_1 = require("./judger_interfaces"); +const interfaces = require("./judger_interfaces"); const compileError = "Compile Error", systemError = "System Error", testdataError = "No Testdata"; exports.statusToString = {}; -exports.statusToString[interfaces_1.TestcaseResultType.Accepted] = "Accepted"; -exports.statusToString[interfaces_1.TestcaseResultType.WrongAnswer] = "Wrong Answer"; -exports.statusToString[interfaces_1.TestcaseResultType.PartiallyCorrect] = "Partially Correct"; -exports.statusToString[interfaces_1.TestcaseResultType.MemoryLimitExceeded] = "Memory Limit Exceeded"; -exports.statusToString[interfaces_1.TestcaseResultType.TimeLimitExceeded] = "Time Limit Exceeded"; -exports.statusToString[interfaces_1.TestcaseResultType.OutputLimitExceeded] = "Output Limit Exceeded"; -exports.statusToString[interfaces_1.TestcaseResultType.RuntimeError] = "Runtime Error"; -exports.statusToString[interfaces_1.TestcaseResultType.FileError] = "File Error"; -exports.statusToString[interfaces_1.TestcaseResultType.JudgementFailed] = "Judgement Failed"; -exports.statusToString[interfaces_1.TestcaseResultType.InvalidInteraction] = "Invalid Interaction"; +exports.statusToString[interfaces.TestcaseResultType.Accepted] = "Accepted"; +exports.statusToString[interfaces.TestcaseResultType.WrongAnswer] = "Wrong Answer"; +exports.statusToString[interfaces.TestcaseResultType.PartiallyCorrect] = "Partially Correct"; +exports.statusToString[interfaces.TestcaseResultType.MemoryLimitExceeded] = "Memory Limit Exceeded"; +exports.statusToString[interfaces.TestcaseResultType.TimeLimitExceeded] = "Time Limit Exceeded"; +exports.statusToString[interfaces.TestcaseResultType.OutputLimitExceeded] = "Output Limit Exceeded"; +exports.statusToString[interfaces.TestcaseResultType.RuntimeError] = "Runtime Error"; +exports.statusToString[interfaces.TestcaseResultType.FileError] = "File Error"; +exports.statusToString[interfaces.TestcaseResultType.JudgementFailed] = "Judgement Failed"; +exports.statusToString[interfaces.TestcaseResultType.InvalidInteraction] = "Invalid Interaction"; function firstNonAC(t) { - if (t.every(v => v === interfaces_1.TestcaseResultType.Accepted)) { - return interfaces_1.TestcaseResultType.Accepted; + if (t.every(v => v === interfaces.TestcaseResultType.Accepted)) { + return interfaces.TestcaseResultType.Accepted; } else { - return t.find(r => r !== interfaces_1.TestcaseResultType.Accepted); + return t.find(r => r !== interfaces.TestcaseResultType.Accepted); } } exports.firstNonAC = firstNonAC; function convertResult(taskId, source) { winston.debug(`Converting result for ${taskId}`, source); let time = null, memory = null, score = null, done = true, statusString = null; - if (source.compile && source.compile.status === interfaces_1.TaskStatus.Failed) { + if (source.compile && source.compile.status === interfaces.TaskStatus.Failed) { statusString = compileError; } else if (source.error != null) { done = false; - if (source.error === interfaces_1.ErrorType.TestDataError) { + if (source.error === interfaces.ErrorType.TestDataError) { statusString = testdataError; } else { @@ -49,7 +49,7 @@ function convertResult(taskId, source) { }; time = forEveryTestcase(c => c.time, _.sum); memory = forEveryTestcase(c => c.memory, _.max); - if (source.judge.subtasks.some(s => s.cases.some(c => c.status === interfaces_1.TaskStatus.Failed))) { + if (source.judge.subtasks.some(s => s.cases.some(c => c.status === interfaces.TaskStatus.Failed))) { winston.debug(`Some subtasks failed, returning system error`); statusString = systemError; } @@ -67,7 +67,7 @@ function convertResult(taskId, source) { time: time, memory: memory, score: score, - statusNumber: done ? interfaces_1.TaskStatus.Done : interfaces_1.TaskStatus.Failed, + statusNumber: done ? interfaces.TaskStatus.Done : interfaces.TaskStatus.Failed, statusString: statusString, result: source }; diff --git a/libs/judger.js b/libs/judger.js index aef341f..38cb20c 100644 --- a/libs/judger.js +++ b/libs/judger.js @@ -96,6 +96,7 @@ async function connect () { process.exit(1); }); } +module.exports.connect = connect; module.exports.judge = async function (judge_state, problem, priority) { let type, param, extraData = null; @@ -138,5 +139,3 @@ module.exports.judge = async function (judge_state, problem, priority) { amqpSendChannel.sendToQueue('judge', msgPack.encode({ content: content, extraData: extraData }), { priority: priority }); } - -connect(); diff --git a/modules/socketio.js b/modules/socketio.js index bced125..cd137c1 100644 --- a/modules/socketio.js +++ b/modules/socketio.js @@ -4,8 +4,8 @@ const socketio = require("socket.io"); const diff = require("jsondiffpatch"); const jwt = require("jsonwebtoken"); const winston = require("winston"); -const judgeResult_1 = require("../libs/judgeResult"); -const interfaces_1 = require("../libs/judger_interfaces"); +const judgeResult = require("../libs/judgeResult"); +const interfaces = require("../libs/judger_interfaces"); let ioInstance; let detailProgressNamespace; let roughProgressNamespace; @@ -223,7 +223,7 @@ function createTask(taskId) { exports.createTask = createTask; function updateCompileStatus(taskId, result) { winston.debug(`Updating compilation status for #${taskId}`); - compiledList[taskId] = { result: result.status === interfaces_1.TaskStatus.Done ? 'Submitted' : 'Compile Error' }; + compiledList[taskId] = { result: result.status === interfaces.TaskStatus.Done ? 'Submitted' : 'Compile Error' }; compileProgressNamespace.to(taskId.toString()).emit('finish', { taskId: taskId, result: compiledList[taskId] @@ -261,7 +261,7 @@ function updateResult(taskId, data) { }); } } - const finalResult = judgeResult_1.convertResult(taskId, data); + const finalResult = judgeResult.convertResult(taskId, data); const roughResult = { result: finalResult.statusString, time: finalResult.time,