mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: trigger start when ready
This commit is contained in:
2 files changed
+12
-4
No files matched your search
@@ -196,7 +196,6 @@ export default class Hydro implements Session {
|
|||||||
const content = Object.keys(config).length
|
const content = Object.keys(config).length
|
||||||
? JSON.stringify({ key: 'config', ...config })
|
? JSON.stringify({ key: 'config', ...config })
|
||||||
: '{"key":"ping"}';
|
: '{"key":"ping"}';
|
||||||
setInterval(() => this.ws?.send?.(content), 30000);
|
|
||||||
this.ws.on('message', (data) => {
|
this.ws.on('message', (data) => {
|
||||||
if (data.toString() === 'ping') {
|
if (data.toString() === 'ping') {
|
||||||
this.ws.send('pong');
|
this.ws.send('pong');
|
||||||
@@ -216,6 +215,8 @@ export default class Hydro implements Session {
|
|||||||
});
|
});
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
this.ws.once('open', async () => {
|
this.ws.once('open', async () => {
|
||||||
|
this.ws.send(content);
|
||||||
|
this.ws.send('{"key":"start"}');
|
||||||
if (!this.config.noStatus) {
|
if (!this.config.noStatus) {
|
||||||
const info = await sysinfo.get();
|
const info = await sysinfo.get();
|
||||||
this.ws.send(JSON.stringify({ key: 'status', info }));
|
this.ws.send(JSON.stringify({ key: 'status', info }));
|
||||||
@@ -224,7 +225,6 @@ export default class Hydro implements Session {
|
|||||||
this.ws.send(JSON.stringify({ key: 'status', info: { mid, ...inf } }));
|
this.ws.send(JSON.stringify({ key: 'status', info: { mid, ...inf } }));
|
||||||
}, 1200000);
|
}, 1200000);
|
||||||
}
|
}
|
||||||
this.ws.send(content);
|
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -213,6 +213,7 @@ export class JudgeFileUpdateHandler extends Handler {
|
|||||||
class JudgeConnectionHandler extends ConnectionHandler {
|
class JudgeConnectionHandler extends ConnectionHandler {
|
||||||
category = '#judge';
|
category = '#judge';
|
||||||
processing: Task[] = [];
|
processing: Task[] = [];
|
||||||
|
started = false;
|
||||||
closed = false;
|
closed = false;
|
||||||
query: any = { type: { $in: ['judge', 'generate'] } };
|
query: any = { type: { $in: ['judge', 'generate'] } };
|
||||||
rdocs: Record<string, RecordDoc> = {};
|
rdocs: Record<string, RecordDoc> = {};
|
||||||
@@ -222,9 +223,12 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
|||||||
async prepare() {
|
async prepare() {
|
||||||
logger.info('Judge daemon connected from ', this.request.ip);
|
logger.info('Judge daemon connected from ', this.request.ip);
|
||||||
this.sendLanguageConfig();
|
this.sendLanguageConfig();
|
||||||
// Ensure language sent
|
// TODO deprecated, just for compatibility
|
||||||
await sleep(100);
|
setTimeout(() => {
|
||||||
|
if (this.started || this.closed) return;
|
||||||
this.newTask().catch((e) => logger.error(e));
|
this.newTask().catch((e) => logger.error(e));
|
||||||
|
this.started = true;
|
||||||
|
}, 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@subscribe('system/setting')
|
@subscribe('system/setting')
|
||||||
@@ -291,6 +295,10 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
|||||||
if (msg.lang instanceof Array && msg.lang.every((i) => typeof i === 'string')) {
|
if (msg.lang instanceof Array && msg.lang.every((i) => typeof i === 'string')) {
|
||||||
this.query.lang = { $in: msg.lang };
|
this.query.lang = { $in: msg.lang };
|
||||||
}
|
}
|
||||||
|
} else if (msg.key === 'start') {
|
||||||
|
if (this.started) return;
|
||||||
|
this.newTask().catch((e) => logger.error(e));
|
||||||
|
this.started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user