mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: disable destoryOnError
This commit is contained in:
1 parent
28a5c894f7
commit
0c95620fa0
4 files changed
+20
-22
No files matched your search
@@ -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",
|
||||||
|
|||||||
@@ -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 {
|
||||||
const res = await getFirst(this.filter);
|
// eslint-disable-next-line no-await-in-loop
|
||||||
if (res) {
|
const res = await getFirst(this.filter);
|
||||||
this.running = res;
|
if (res) {
|
||||||
await this.func(res);
|
this.running = res;
|
||||||
this.running = null;
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await this.func(res);
|
||||||
|
this.running = null;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
if (this.destoryOnError) this.destory();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
logger.error(e);
|
|
||||||
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,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",
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in new issue
Block a user