Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Application , IPlugin} from 'pinus';
import { Robot, RobotCfg } from 'pinus-robot';
import * as fs from 'fs';
import * as yargs from 'yargs';
let argv = yargs.argv;
console.log('启动robotAgent');
let config = {
master: {host: argv.host, port: argv.port, interval: argv.interval}
} as RobotCfg;
let robot = new Robot(config);
robot.runAgent(argv.scriptFile as any);
process.on('uncaughtException', function (err) {
console.error(' Caught exception: ' + err.stack);
if (!!robot && !!robot.agent) {
// robot.agent.socket.emit('crash', err.stack);
}
fs.appendFile('./log/.log', err.stack, function (err) { });
});
afterStartAll(app: Application): void {
let robot = new Robot(this.conf);
let mode = 'master';
let scriptFile = path.normalize(this.conf.scriptFile);
if(path.sep === '\\') {
scriptFile = scriptFile.replace(/\\/g , '\\\\');
}
// 启动机器人总管
robot.runMaster(`"${__dirname}/robotAgent.js" --host=${this.conf.master.host} --port=${this.conf.master.port} --interval=${this.conf.master.interval} --scriptFile="${scriptFile}"`);
}
}
import * as http from 'http';
let envConfig = require('./app/config/env.json');
let config = require('./app/config/' + envConfig.env + '/config');
let path = __filename.substring(0, __filename.lastIndexOf('/'));
import { Robot } from 'pinus-robot';
import * as cluster from 'cluster';
let robot = new Robot(config);
function run(num) {
for (let i = 0; i < num; i++) {
cluster.fork();
}
}
function stop() {
for (let id in cluster.workers) {
cluster.workers[id].process.kill();
}
}
function startHttp() {
http.createServer(function (req, res) {
if (req.method === 'GET') {
let envConfig = require('./app/config/env.json');
let config = require('./app/config/' + envConfig.env + '/config');
import { Robot } from 'pinus-robot';
import * as fs from 'fs';
let robot = new Robot(config);
let mode = 'master';
if (process.argv.length > 2) {
mode = process.argv[2];
}
if (mode !== 'master' && mode !== 'client') {
throw new Error(' mode must be master or client');
}
if (mode === 'master') {
robot.runMaster(__filename);
} else {
let script = (process.cwd() + envConfig.script);
robot.runAgent(script);
}