mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: 可调的性能设置
This commit is contained in:
1 parent
8c8dcb89eb
commit
2bf1a18890
21 files changed
+237
-274
No files matched your search
@@ -12,10 +12,9 @@
|
||||
`-.__ 听取人生经验。 __.-'
|
||||
````- - -.......- - -''' ~
|
||||
~ */
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'js-yaml';
|
||||
import * as Session from './hosts/index';
|
||||
import { sleep, Queue } from './utils';
|
||||
import { getConfig } from './config';
|
||||
import log from './log';
|
||||
|
||||
declare global {
|
||||
@@ -30,8 +29,6 @@ if (!global.onDestory) global.onDestory = [];
|
||||
if (!global.hosts) global.hosts = [];
|
||||
let SI = false;
|
||||
|
||||
const { RETRY_DELAY_SEC, CONFIG_FILE, CONFIG } = require('./config');
|
||||
|
||||
const terminate = async () => {
|
||||
log.info('正在保存数据');
|
||||
try {
|
||||
@@ -52,42 +49,16 @@ process.on('unhandledRejection', (reason, p) => {
|
||||
});
|
||||
|
||||
async function daemon() {
|
||||
let config;
|
||||
try {
|
||||
if (CONFIG) config = CONFIG;
|
||||
else {
|
||||
config = (await fs.readFile(CONFIG_FILE)).toString();
|
||||
config = yaml.load(config);
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('配置文件无效或未找到。');
|
||||
process.exit(1);
|
||||
}
|
||||
const _hosts = getConfig('hosts');
|
||||
const retry_delay_sec = getConfig('retry_delay_sec');
|
||||
const hosts = {};
|
||||
const queue = new Queue<any>();
|
||||
for (const i in config.hosts) {
|
||||
config.hosts[i].host = i;
|
||||
hosts[i] = new Session[config.hosts[i].type || 'vj4'](config.hosts[i]);
|
||||
for (const i in _hosts) {
|
||||
_hosts[i].host = i;
|
||||
hosts[i] = new Session[_hosts[i].type || 'vj4'](_hosts[i]);
|
||||
await hosts[i].init();
|
||||
}
|
||||
global.hosts = hosts;
|
||||
if (!CONFIG) {
|
||||
global.onDestory.push(async () => {
|
||||
const cfg = { hosts: {} };
|
||||
for (const i in hosts) {
|
||||
cfg.hosts[i] = {
|
||||
host: i,
|
||||
type: hosts[i].config.type || 'default',
|
||||
uname: hosts[i].config.uname,
|
||||
password: hosts[i].config.password,
|
||||
server_url: hosts[i].config.server_url,
|
||||
};
|
||||
if (hosts[i].config.cookie) cfg.hosts[i].cookie = hosts[i].config.cookie;
|
||||
if (hosts[i].config.detail) cfg.hosts[i].detail = hosts[i].config.detail;
|
||||
}
|
||||
await fs.writeFile(CONFIG_FILE, yaml.dump(cfg));
|
||||
});
|
||||
}
|
||||
while ('Orz twd2') {
|
||||
try {
|
||||
for (const i in hosts) await hosts[i].consume(queue);
|
||||
@@ -97,11 +68,11 @@ async function daemon() {
|
||||
}
|
||||
} catch (e) {
|
||||
log.error(e, e.stack);
|
||||
log.info(`在 ${RETRY_DELAY_SEC} 秒后重试`);
|
||||
await sleep(RETRY_DELAY_SEC * 1000);
|
||||
log.info(`在 ${retry_delay_sec} 秒后重试`);
|
||||
await sleep(retry_delay_sec * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!module.parent) daemon();
|
||||
if (require.main === module) daemon();
|
||||
export = daemon;
|
||||
Reference in new issue
Block a user