function createWorkerProcess(process) { const options = createProcessOptions(process); cluster.setupMaster(options); return cluster.fork(options.env); }
constructor(work, options) { super(); if (!work || typeof work !== 'function') { throw new Error('You need to provide a worker function.'); } this.keepAlive = options.keepAlive === undefined ? true : options.keepAlive; this.monitor = options.monitor === undefined ? true : options.monitor; this.work = work.bind(this); this.fork = this.fork.bind(this); this.stop = this.stop.bind(this); if (cluster.isMaster) { cluster.setupMaster({ silent: true }); // Is the process from the master process needs to be piped into the workers. // cluster.fork().process.stdout.pipe(process.stdout); } if (cluster.isWorker) { this.work(); return messageHandler.bind(null, process)(); } return this.start(options); }
constructor (token, count, logger) { this.cluster = cluster; this.cluster.setupMaster({ exec: "GAwesomeBot.js", }); this.logger = logger; this.token = token ? token : process.env.CLIENT_TOKEN; this.host = process.env.GAB_HOST ? process.env.GAB_HOST : undefined; this.count = count; this.mode = process.env.NODE_ENV === "production" ? "production" : "development"; this.SharderIPC = require("./").SharderIPC; this.Collection = require("discord.js").Collection; this.IPC = new this.SharderIPC(this, logger); this.shards = new this.Collection(); this.guilds = new this.Collection(); this.shutdown = false; }
cluster.setupMaster({exec: script}); this._worker = cluster.fork(env);
constructor(work, options) { super(); if (!work || typeof work !== 'function') { throw new Error('You need to provide a worker function.'); } this.keepAlive = options.keepAlive === undefined ? true : options.keepAlive; this.monitor = options.monitor === undefined ? true : options.monitor; this.work = work.bind(this); this.fork = this.fork.bind(this); this.stop = this.stop.bind(this); if (cluster.isMaster) { cluster.setupMaster({ silent: true }); // Is the process from the master process needs to be piped into the workers. // cluster.fork().process.stdout.pipe(process.stdout); } if (cluster.isWorker) { this.work(); return messageHandler.bind(null, process)(); } return this.start(options); }