vjudge: disable destoryOnError

This commit is contained in:
undefined committed 2021-07-31 03:28:10 +08:00
1 parent 28a5c894f7
commit 0c95620fa0
4 files changed
+13 -15

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.30.2", "version": "2.30.3",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+10 -12
View File
@@ -26,35 +26,33 @@ async function getFirst(query: FilterQuery<Task>) {
class Consumer { class Consumer {
consuming: boolean; consuming: boolean;
running?: any; running?: any;
timeout: NodeJS.Timeout;
constructor(public filter: any, public func: Function, public destoryOnError = true) { constructor(public filter: any, public func: Function, public destoryOnError = true) {
this.consuming = true; this.consuming = true;
this.get = this.get.bind(this); this.consume();
this.get();
this.destory = this.destory.bind(this);
bus.on('app/exit', this.destory); bus.on('app/exit', this.destory);
} }
async get() { async consume() {
if (this.running || !this.consuming) return; while (this.consuming) {
try { try {
// eslint-disable-next-line no-await-in-loop
const res = await getFirst(this.filter); const res = await getFirst(this.filter);
if (res) { if (res) {
this.running = res; this.running = res;
// eslint-disable-next-line no-await-in-loop
await this.func(res); await this.func(res);
this.running = null; this.running = null;
} }
} catch (e) { } catch (err) {
logger.error(e); logger.error(err);
if (this.destoryOnError) this.destory(); if (this.destoryOnError) this.destory();
} }
this.timeout = setTimeout(this.get, 100); }
} }
async destory() { async destory() {
this.consuming = false; this.consuming = false;
clearTimeout(this.timeout);
} }
} }
@@ -123,8 +121,8 @@ class TaskModel {
return [0, now]; return [0, now];
} }
static async consume(query: any, cb: Function) { static async consume(query: any, cb: Function, destoryOnError = true) {
return new Consumer(query, cb); return new Consumer(query, cb, destoryOnError);
} }
static Consumer = Consumer; static Consumer = Consumer;
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/vjudge", "name": "@hydrooj/vjudge",
"version": "1.2.0", "version": "1.2.1",
"description": "Submit problems to remote oj", "description": "Submit problems to remote oj",
"main": "package.json", "main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+1 -1
View File
@@ -79,7 +79,7 @@ class Service {
const res = await this.login(); const res = await this.login();
if (!res) return; if (!res) return;
setInterval(() => this.login(), 1 * 3600 * 1000); setInterval(() => this.login(), 1 * 3600 * 1000);
TaskModel.consume({ type: 'remotejudge', subType: this.account.type }, this.judge.bind(this)); TaskModel.consume({ type: 'remotejudge', subType: this.account.type }, this.judge.bind(this), false);
const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray(); const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray();
for (const ddoc of ddocs) { for (const ddoc of ddocs) {
if (!ddoc.syncDone) await this.sync(ddoc._id, false); if (!ddoc.syncDone) await this.sync(ddoc._id, false);