mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +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",
|
||||
"version": "2.30.2",
|
||||
"version": "2.30.3",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -26,35 +26,33 @@ async function getFirst(query: FilterQuery<Task>) {
|
||||
class Consumer {
|
||||
consuming: boolean;
|
||||
running?: any;
|
||||
timeout: NodeJS.Timeout;
|
||||
|
||||
constructor(public filter: any, public func: Function, public destoryOnError = true) {
|
||||
this.consuming = true;
|
||||
this.get = this.get.bind(this);
|
||||
this.get();
|
||||
this.destory = this.destory.bind(this);
|
||||
this.consume();
|
||||
bus.on('app/exit', this.destory);
|
||||
}
|
||||
|
||||
async get() {
|
||||
if (this.running || !this.consuming) return;
|
||||
try {
|
||||
const res = await getFirst(this.filter);
|
||||
if (res) {
|
||||
this.running = res;
|
||||
await this.func(res);
|
||||
this.running = null;
|
||||
async consume() {
|
||||
while (this.consuming) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const res = await getFirst(this.filter);
|
||||
if (res) {
|
||||
this.running = res;
|
||||
// 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() {
|
||||
this.consuming = false;
|
||||
clearTimeout(this.timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +121,8 @@ class TaskModel {
|
||||
return [0, now];
|
||||
}
|
||||
|
||||
static async consume(query: any, cb: Function) {
|
||||
return new Consumer(query, cb);
|
||||
static async consume(query: any, cb: Function, destoryOnError = true) {
|
||||
return new Consumer(query, cb, destoryOnError);
|
||||
}
|
||||
|
||||
static Consumer = Consumer;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/vjudge",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "Submit problems to remote oj",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -79,7 +79,7 @@ class Service {
|
||||
const res = await this.login();
|
||||
if (!res) return;
|
||||
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();
|
||||
for (const ddoc of ddocs) {
|
||||
if (!ddoc.syncDone) await this.sync(ddoc._id, false);
|
||||
|
||||
Reference in new issue
Block a user