core: 评测机离线后停止未完成的任务分配

fixes #60
pull/61/head
undefined 4 years ago
parent 8018a79418
commit 2ac6cb3745

@ -27,7 +27,7 @@ jobs:
- name: Build - name: Build
run: yarn build run: yarn build
- name: Lint - name: Lint
run: yarn lint run: yarn lint:ci
- name: Unit Test - name: Unit Test
run: yarn jest --runInBand run: yarn jest --runInBand
- name: Report Coverage - name: Report Coverage

@ -9,6 +9,7 @@
"build": "node build/build.js", "build": "node build/build.js",
"build:watch": "node build/build.js --watch", "build:watch": "node build/build.js --watch",
"lint": "eslint packages --ext ts --fix", "lint": "eslint packages --ext ts --fix",
"lint:ci": "eslint packages --ext ts",
"pub": "node build/publish", "pub": "node build/publish",
"jest": "node build/jest", "jest": "node build/jest",
"debug": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug", "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug",

@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.20.27", "version": "2.20.28",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",

@ -112,8 +112,10 @@ export class JudgeFilesDownloadHandler extends Handler {
class JudgeConnectionHandler extends ConnectionHandler { class JudgeConnectionHandler extends ConnectionHandler {
processing: any = null; processing: any = null;
closed = false;
async prepare() { async prepare() {
logger.info('Judge daemon connected from ', this.request.ip);
this.newTask(); this.newTask();
} }
@ -123,6 +125,7 @@ class JudgeConnectionHandler extends ConnectionHandler {
while (!t) { while (!t) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await sleep(100); await sleep(100);
if (this.closed) return;
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
t = await task.getFirst({ type: 'judge' }); t = await task.getFirst({ type: 'judge' });
} }
@ -146,10 +149,12 @@ class JudgeConnectionHandler extends ConnectionHandler {
} }
async cleanup() { async cleanup() {
logger.info('Judge daemon disconnected from ', this.request.ip);
if (this.processing) { if (this.processing) {
await record.reset(this.processing.domainId, this.processing.rid, false); await record.reset(this.processing.domainId, this.processing.rid, false);
await task.add(this.processing); await task.add(this.processing);
} }
this.closed = true;
} }
} }

Loading…
Cancel
Save