From 156d931811c91160df614c9a3cd5434d710add37 Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 27 Oct 2020 13:05:29 +0800 Subject: [PATCH] judge: daemon mode --- packages/hydrojudge/bin/hydrojudge.js | 2 +- packages/hydrojudge/package.json | 5 +++-- packages/hydrojudge/src/checkers.ts | 2 +- packages/hydrojudge/src/compile.ts | 2 +- packages/hydrojudge/src/error.ts | 2 +- packages/hydrojudge/src/judge/default.ts | 2 +- packages/hydrojudge/src/judge/hack.ts | 2 +- packages/hydrojudge/src/judge/interactive.ts | 4 ++-- packages/hydrojudge/src/judge/run.ts | 2 +- packages/hydrojudge/src/judge/submit_answer.ts | 2 +- packages/hydrojudge/src/sandbox.ts | 2 +- packages/hydrojudge/src/tmpfs.ts | 5 ++--- 12 files changed, 16 insertions(+), 16 deletions(-) mode change 100644 => 100755 packages/hydrojudge/bin/hydrojudge.js diff --git a/packages/hydrojudge/bin/hydrojudge.js b/packages/hydrojudge/bin/hydrojudge.js old mode 100644 new mode 100755 index 1d7052b5e..c30eeea90 --- a/packages/hydrojudge/bin/hydrojudge.js +++ b/packages/hydrojudge/bin/hydrojudge.js @@ -1,3 +1,3 @@ #!/bin/env node -require('./dist/daemon')() \ No newline at end of file +require('../dist/daemon')(); diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 613e9fb79..45fd0f053 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,6 +1,7 @@ { "name": "@hydrooj/hydrojudge", - "version": "2.0.15", + "bin": "bin/hydrojudge.js", + "version": "2.1.0", "main": "package.json", "author": "masnn", "dependencies": { @@ -28,4 +29,4 @@ "build": "tsc", "lint": "eslint . --ext ts --fix" } -} +} \ No newline at end of file diff --git a/packages/hydrojudge/src/checkers.ts b/packages/hydrojudge/src/checkers.ts index 0f033cf95..61342f881 100644 --- a/packages/hydrojudge/src/checkers.ts +++ b/packages/hydrojudge/src/checkers.ts @@ -1,6 +1,6 @@ /* eslint-disable no-template-curly-in-string */ -import { STATUS } from 'hydrooj/dist/model/builtin'; import fs from 'fs-extra'; +import * as STATUS from './status'; import { run } from './sandbox'; import { SystemError } from './error'; diff --git a/packages/hydrojudge/src/compile.ts b/packages/hydrojudge/src/compile.ts index 38edb01d8..70a16adba 100644 --- a/packages/hydrojudge/src/compile.ts +++ b/packages/hydrojudge/src/compile.ts @@ -1,5 +1,5 @@ import yaml from 'js-yaml'; -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from './status'; import { run, del } from './sandbox'; import { CompileError, SystemError } from './error'; import { compilerText } from './utils'; diff --git a/packages/hydrojudge/src/error.ts b/packages/hydrojudge/src/error.ts index f11799c43..4877e91aa 100644 --- a/packages/hydrojudge/src/error.ts +++ b/packages/hydrojudge/src/error.ts @@ -1,4 +1,4 @@ -import { STATUS_TEXTS } from 'hydrooj/dist/model/builtin'; +import { STATUS_TEXTS } from './status'; export class CompileError extends Error { stdout: string; diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index f804e93dc..8d0cb0fed 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -2,7 +2,7 @@ import Queue from 'p-queue'; import path from 'path'; import fs from 'fs-extra'; import { argv } from 'yargs'; -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from '../status'; import { CompileError, SystemError } from '../error'; import { copyInDir, parseFilename } from '../utils'; import { run } from '../sandbox'; diff --git a/packages/hydrojudge/src/judge/hack.ts b/packages/hydrojudge/src/judge/hack.ts index b324ff2fd..2abe8d350 100644 --- a/packages/hydrojudge/src/judge/hack.ts +++ b/packages/hydrojudge/src/judge/hack.ts @@ -1,7 +1,7 @@ // Not implemented import path from 'path'; import fs from 'fs-extra'; -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from '../status'; import { CompileError } from '../error'; import { copyInDir, parseFilename } from '../utils'; import { run } from '../sandbox'; diff --git a/packages/hydrojudge/src/judge/interactive.ts b/packages/hydrojudge/src/judge/interactive.ts index c694b15c3..6ae137314 100644 --- a/packages/hydrojudge/src/judge/interactive.ts +++ b/packages/hydrojudge/src/judge/interactive.ts @@ -1,6 +1,6 @@ import Queue from 'p-queue'; import fs from 'fs-extra'; -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from '../status'; import { parseFilename } from '../utils'; import { run } from '../sandbox'; import compile from '../compile'; @@ -39,7 +39,7 @@ function judgeCase(c) { status = STATUS.STATUS_RUNTIME_ERROR; if (code < 32) message = signals[code]; else message = `您的程序返回了 ${code}.`; - } else [status, score, message] = resInteractor.files.stderr.split('\n'); + } else[status, score, message] = resInteractor.files.stderr.split('\n'); ctxSubtask.score = Score[ctxSubtask.subtask.type](ctxSubtask.score, score); ctxSubtask.status = Math.max(ctxSubtask.status, status); ctx.total_time_usage_ms += time_usage_ms; diff --git a/packages/hydrojudge/src/judge/run.ts b/packages/hydrojudge/src/judge/run.ts index 886e14d84..7c8c5e0b3 100644 --- a/packages/hydrojudge/src/judge/run.ts +++ b/packages/hydrojudge/src/judge/run.ts @@ -1,7 +1,7 @@ import fs from 'fs-extra'; import path from 'path'; import { argv } from 'yargs'; -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from '../status'; import { run } from '../sandbox'; import compile from '../compile'; import signals from '../signals'; diff --git a/packages/hydrojudge/src/judge/submit_answer.ts b/packages/hydrojudge/src/judge/submit_answer.ts index bcc60a91c..3ba1e5f5c 100644 --- a/packages/hydrojudge/src/judge/submit_answer.ts +++ b/packages/hydrojudge/src/judge/submit_answer.ts @@ -1,4 +1,4 @@ -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from '../status'; import { check } from '../check'; export async function judge({ diff --git a/packages/hydrojudge/src/sandbox.ts b/packages/hydrojudge/src/sandbox.ts index ae1b88733..bda6a2485 100644 --- a/packages/hydrojudge/src/sandbox.ts +++ b/packages/hydrojudge/src/sandbox.ts @@ -1,6 +1,6 @@ import Axios from 'axios'; import fs from 'fs-extra'; -import { STATUS } from 'hydrooj/dist/model/builtin'; +import * as STATUS from './status'; import { SystemError } from './error'; import { cmd } from './utils'; diff --git a/packages/hydrojudge/src/tmpfs.ts b/packages/hydrojudge/src/tmpfs.ts index 14d13cb6c..c3ffb6882 100644 --- a/packages/hydrojudge/src/tmpfs.ts +++ b/packages/hydrojudge/src/tmpfs.ts @@ -1,11 +1,10 @@ import child from 'child_process'; import fs from 'fs-extra'; import os from 'os'; -import { Logger } from 'hydrooj/dist/logger'; +import log from './log'; -const logger = new Logger('judge'); const linux = os.platform() === 'linux'; -if (!linux) logger.warn('Not running on linux. tmpfs disabled.'); +if (!linux) log.warn('Not running on linux. tmpfs disabled.'); export function mount(path: string, size = '32m') { fs.ensureDirSync(path);