mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: enhanced pm2 detection
This commit is contained in:
1 parent
0562661fb4
commit
2f2b1ca711
5 files changed
+24
-9
No files matched your search
@@ -67,10 +67,6 @@
|
||||
"@types/semver": "^7.3.12",
|
||||
"@types/serialize-javascript": "^5.0.2",
|
||||
"@types/superagent": "^4.1.15",
|
||||
"moment": "^2.29.4",
|
||||
"pm2": "^5.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pm2": "*"
|
||||
"moment": "^2.29.4"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { hostname } from 'os';
|
||||
import moment from 'moment-timezone';
|
||||
import { FilterQuery, ObjectID } from 'mongodb';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||
import { BaseService, EventDoc, Task } from '../interface';
|
||||
import { Logger } from '../logger';
|
||||
@@ -139,7 +140,7 @@ class TaskModel {
|
||||
static Worker = Worker;
|
||||
}
|
||||
|
||||
const id = hostname();
|
||||
const id = process.env.exec_mode === 'cluster_mode' ? hostname() : nanoid();
|
||||
Worker.addHandler('task.daily', async () => {
|
||||
await global.Hydro.model.record.coll.deleteMany({ contest: new ObjectID('000000000000000000000000') });
|
||||
await global.Hydro.script.rp?.run({}, new Logger('task/rp').debug);
|
||||
|
||||
@@ -3,6 +3,7 @@ import cac from 'cac';
|
||||
import type {
|
||||
Db, FilterQuery, ObjectID, OnlyFieldsOfType,
|
||||
} from 'mongodb';
|
||||
import pm2 from '@hydrooj/utils/lib/locate-pm2';
|
||||
import type { ProblemSolutionHandler } from '../handler/problem';
|
||||
import type { UserRegisterHandler } from '../handler/user';
|
||||
import type {
|
||||
@@ -191,8 +192,7 @@ export function broadcast<K extends keyof EventMap>(event: K, ...payload: Parame
|
||||
}
|
||||
|
||||
try {
|
||||
if (!process.send) throw new Error();
|
||||
const pm2: typeof import('pm2') = require('pm2');
|
||||
if (!process.send || !pm2 || process.env.exec_mode !== 'cluster_mode') throw new Error();
|
||||
pm2.launchBus((err, bus) => {
|
||||
if (err) throw new Error();
|
||||
bus.on('hydro:broadcast', (packet) => {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const PATH = process.env.PATH?.split(':') || [];
|
||||
|
||||
// @ts-ignore
|
||||
const pm2: typeof import('pm2') | null = (() => {
|
||||
for (const dir of PATH) {
|
||||
try {
|
||||
const info = fs.readlinkSync(path.resolve(dir, 'pm2'));
|
||||
const p = path.resolve(dir, info);
|
||||
return require(`${p.split('.bin')[0]}pm2`); // eslint-disable-line import/no-dynamic-require
|
||||
} catch (e) { }
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
|
||||
export default pm2;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/utils",
|
||||
"version": "1.3.6",
|
||||
"version": "1.3.7",
|
||||
"description": "hydrooj utils",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
Reference in new issue
Block a user