mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: remove onDestory hook
This commit is contained in:
1 parent
d483531b0e
commit
407de23240
1 file changed
+2
-13
@@ -20,22 +20,13 @@ import { getConfig } from './config';
|
|||||||
import HydroHost from './hosts/hydro';
|
import HydroHost from './hosts/hydro';
|
||||||
import log from './log';
|
import log from './log';
|
||||||
|
|
||||||
declare global {
|
const hosts: Record<string, HydroHost> = {};
|
||||||
namespace NodeJS {
|
|
||||||
interface Global {
|
|
||||||
onDestroy: Function[]
|
|
||||||
hosts: any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global.onDestroy ||= [];
|
|
||||||
global.hosts ||= {};
|
|
||||||
let exit = false;
|
let exit = false;
|
||||||
|
|
||||||
const terminate = async () => {
|
const terminate = async () => {
|
||||||
log.info('正在保存数据');
|
log.info('正在保存数据');
|
||||||
try {
|
try {
|
||||||
await Promise.all(Object.values(global.hosts).map((f) => f.dispose?.()));
|
await Promise.all(Object.values(hosts).map((f) => f.dispose?.()));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (exit) process.exit(1);
|
if (exit) process.exit(1);
|
||||||
@@ -53,7 +44,6 @@ process.on('unhandledRejection', (reason, p) => {
|
|||||||
|
|
||||||
async function daemon() {
|
async function daemon() {
|
||||||
const _hosts = getConfig('hosts');
|
const _hosts = getConfig('hosts');
|
||||||
const hosts = {};
|
|
||||||
const queue = new PQueue({ concurrency: Infinity });
|
const queue = new PQueue({ concurrency: Infinity });
|
||||||
queue.on('error', (e) => log.error(e));
|
queue.on('error', (e) => log.error(e));
|
||||||
for (const i in _hosts) {
|
for (const i in _hosts) {
|
||||||
@@ -62,7 +52,6 @@ async function daemon() {
|
|||||||
await hosts[i].init();
|
await hosts[i].init();
|
||||||
}
|
}
|
||||||
for (const i in hosts) hosts[i].consume(queue);
|
for (const i in hosts) hosts[i].consume(queue);
|
||||||
global.hosts = hosts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module) daemon();
|
if (require.main === module) daemon();
|
||||||
|
|||||||
Reference in new issue
Block a user