@foxpage/foxpage-node-sdk
Version:
foxpage node sdk
35 lines (34 loc) • 962 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.initPm2 = exports.withPm2 = void 0;
const foxpage_manager_1 = require("@foxpage/foxpage-manager");
const common_1 = require("../common");
const pm2_1 = require("./pm2");
/**
* init pm2
*/
function withPm2() {
const pm2 = (0, pm2_1.getPm2)();
if (!(pm2 === null || pm2 === void 0 ? void 0 : pm2.isPm2)) {
return null;
}
console.log(`I'm ${pm2.isMaster ? 'master' : 'worker'}`);
const apps = (0, foxpage_manager_1.getApplications)();
// pm2 receive master broadcast then to refresh app
if (pm2.isWorker) {
pm2.onMessage(data => {
apps.forEach(app => {
app.refresh(data);
});
});
}
}
exports.withPm2 = withPm2;
/**
* create pm2
*/
async function initPm2() {
const pm2Config = common_1.config.get('pm2');
await (0, pm2_1.createPm2)(pm2Config);
}
exports.initPm2 = initPm2;