Browse Source

taskId: number to string

master
t123yh 7 years ago
parent
commit
4fddb5dd69
  1. 2
      src/daemon-frontend-syzoj/rmq.ts
  2. 29
      src/daemon-frontend-syzoj/socketio.ts
  3. 2
      src/daemon/interfaces.ts
  4. 2
      src/interfaces.ts
  5. 10
      src/judgeResult.ts

2
src/daemon-frontend-syzoj/rmq.ts

@ -63,7 +63,7 @@ export async function waitForProgress(handle: (result: ProgressReportData) => Pr
});
}
export async function reportReported(taskId: number) {
export async function reportReported(taskId: string) {
winston.verbose('Reporting report finished: ' + taskId);
const payload = msgpack.encode({ type: ProgressReportType.Reported, taskId: taskId });
publicChannel.publish(rmqCommon.progressExchangeName, '', payload);

29
src/daemon-frontend-syzoj/socketio.ts

@ -23,15 +23,15 @@ let roughProgressNamespace: SocketIO.Namespace;
// can only see whether his / her submission is successfully compiled.
let compileProgressNamespace: SocketIO.Namespace;
const currentJudgeList: OverallResult[] = [];
const finishedJudgeList: RoughResult[] = [];
const currentJudgeList: { [taskId: string]: OverallResult } = {};
const finishedJudgeList: { [taskId: string]: RoughResult } = {};
const compiledList = [];
// The detail progress is pushed to client in the delta form.
// However, the messages may arrive in an unorder form.
// In that case, the client will re-connect the server.
const clientDetailProgressList: { [id: string]: { version: number, content: OverallResult } } = {};
const clientDisplayConfigList: { [id: string]: DisplayConfig } = {};
const clientDetailProgressList: { [clientId: string]: { version: number, content: OverallResult } } = {};
const clientDisplayConfigList: { [clientId: string]: DisplayConfig } = {};
interface DisplayConfig {
showScore: boolean;
@ -98,7 +98,7 @@ function processRoughResult(source: RoughResult, config: DisplayConfig): RoughRe
};
}
function forAllClients(ns: SocketIO.Namespace, taskId: number, exec: (socketId: string) => void): void {
function forAllClients(ns: SocketIO.Namespace, taskId: string, exec: (socketId: string) => void): void {
ns.in(taskId.toString()).clients((err, clients) => {
if (!err) {
clients.forEach(client => {
@ -132,6 +132,7 @@ export function initializeSocketIO(s: http.Server) {
if (req.type !== name) {
throw new Error("Request type in token mismatch.");
}
clientDisplayConfigList[socket.id] = req.displayConfig;
} catch (err) {
winston.info('The client has an incorrect token.');
cb({
@ -235,14 +236,15 @@ export function initializeSocketIO(s: http.Server) {
});
}
export function createTask(taskId: number) {
export function createTask(taskId: string) {
winston.debug(`Judge task #${taskId} has started`);
currentJudgeList[taskId] = {};
finishedJudgeList[taskId] = null;
forAllClients(detailProgressNamespace, taskId, (clientId) => {
clientDetailProgressList[clientId] = {
version: 0,
content: currentJudgeList[taskId]
content: {}
};
});
@ -251,7 +253,7 @@ export function createTask(taskId: number) {
compileProgressNamespace.to(taskId.toString()).emit("start", { taskId: taskId });
}
export function updateCompileStatus(taskId: number, result: CompilationResult) {
export function updateCompileStatus(taskId: string, result: CompilationResult) {
winston.debug(`Updating compilation status for #${taskId}`);
compiledList[taskId] = { result: result.status === TaskStatus.Done ? 'Submitted' : 'Compile Error' };
@ -261,7 +263,7 @@ export function updateCompileStatus(taskId: number, result: CompilationResult) {
});
}
export function updateProgress(taskId: number, data: OverallResult) {
export function updateProgress(taskId: string, data: OverallResult) {
winston.verbose(`Updating progress for #${taskId}, data: ${JSON.stringify(data)}`);
currentJudgeList[taskId] = data;
@ -270,19 +272,20 @@ export function updateProgress(taskId: number, data: OverallResult) {
if (clientDetailProgressList[client] && clientDisplayConfigList[client]) { // avoid race condition
const original = clientDetailProgressList[client].content;
const updated = processOverallResult(currentJudgeList[taskId], clientDisplayConfigList[client]);
const version = clientDetailProgressList[taskId].version;
const version = clientDetailProgressList[client].version;
winston.warn("Original: " + JSON.stringify(original) + "\n Updated: " + JSON.stringify(updated));
detailProgressNamespace.sockets[client].emit('update', {
taskId: taskId,
from: version,
to: version + 1,
delta: diff.diff(original, updated)
})
clientDetailProgressList[taskId].version++;
clientDetailProgressList[client].version++;
}
});
}
export function updateResult(taskId: number, data: OverallResult) {
export function updateResult(taskId: string, data: OverallResult) {
currentJudgeList[taskId] = data;
if (compiledList[taskId] == null) {
@ -325,7 +328,7 @@ export function updateResult(taskId: number, data: OverallResult) {
});
}
export function cleanupProgress(taskId: number) {
export function cleanupProgress(taskId: string) {
// Prevent race condition
setTimeout(() => { delete currentJudgeList[taskId]; }, 10000);
}

2
src/daemon/interfaces.ts

@ -8,7 +8,7 @@ export enum ProblemType {
}
export interface JudgeTaskContent {
taskId: number;
taskId: string;
testData: string;
type: ProblemType;
priority: number;

2
src/interfaces.ts

@ -140,7 +140,7 @@ export enum ProgressReportType {
}
export interface ProgressReportData {
taskId: number;
taskId: string;
type: ProgressReportType;
progress: OverallResult | CompilationResult;
}

10
src/judgeResult.ts

@ -3,7 +3,7 @@ import winston = require('winston');
import { JudgeResult, OverallResult, TestcaseResultType, TaskStatus, ErrorType, SubtaskResult, TestcaseResult, TestcaseDetails } from './interfaces';
export interface JudgeResultSubmit {
taskId: number;
taskId: string;
time: number;
memory: number;
score: number;
@ -36,8 +36,8 @@ export function firstNonAC(t: TestcaseResultType[]): TestcaseResultType {
}
}
export function convertResult(id: number, source: OverallResult): JudgeResultSubmit {
winston.debug(`Converting result for ${id}`, source);
export function convertResult(taskId: string, source: OverallResult): JudgeResultSubmit {
winston.debug(`Converting result for ${taskId}`, source);
let time = NaN,
memory = NaN,
score = NaN,
@ -77,7 +77,7 @@ export function convertResult(id: number, source: OverallResult): JudgeResultSub
}
const result = {
taskId: id,
taskId: taskId,
time: time,
memory: memory,
score: score,
@ -85,6 +85,6 @@ export function convertResult(id: number, source: OverallResult): JudgeResultSub
statusString: statusString,
result: source
};
winston.debug(`Result for ${id}`, result);
winston.debug(`Result for ${taskId}`, result);
return result;
}
Loading…
Cancel
Save