// Respond to master's requests for worker's local metrics. process.on('message', message => { if (cluster().isWorker && message.type === GET_METRICS_REQ) { Promise.all(registries.map(r => r.getMetricsAsJSON())) .then(metrics => { process.send({ type: GET_METRICS_RES, requestId: message.requestId, metrics, }); }) .catch(error => { process.send({ type: GET_METRICS_RES, requestId: message.requestId, error: error.message, }); }); } });
stop() { // Destroy server and available connections. this.server.destroy(); if (cluster.isWorker && this.config.environment === 'development' && get(this.config, 'currentEnvironment.server.autoReload.enabled', true) === true) { process.send('stop'); } // Kill process. process.exit(0); }
const restart = path => { if (strapi.reload.isWatching && cluster.isWorker && !strapi.reload.isReloading) { strapi.reload.isReloading = true; strapi.log.info(`File changed: ${path}`); strapi.reload(); } }
reload() { const reload = function () { if (cluster.isWorker && this.config.environment === 'development' && get(this.config, 'currentEnvironment.server.autoReload.enabled', true) === true) { process.send('reload'); } }; reload.isReloading = false; reload.isWatching = true; return reload; }
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); }
const clusterId = cluster.isWorker ? cluster.worker.id : ''; const tempName = 'hc_' + os.hostname() + '_' + clusterId + '_' + Math.round(Math.random() * HEALTH_CHECK_KEY_MAX); const tempBuffer = Buffer.from([1, 2, 3, 4, 5]);
constructor() { super(); if (cluster.isWorker) { this._status = WorkerStatuses.INITIALIZED;
if (cluster.isWorker) {
}); if (cluster.isWorker) {
if (cluster.isWorker) { storage.trigger('fatalError', 'Workers are not allowed to create threads')
if (cluster.isWorker) {
_start() { if (cluster.isWorker) { cluster.worker.on('disconnect', () => this.stop() this._heapwatchHandle.setGCMonitor(); if (cluster.isWorker) { this._setupWorkerHeartBeat(); if (cluster.isWorker) { this._ratelimiter = new RateLimiterWorker(this.config.ratelimiter); } else { this._serviceReturns = res; if (cluster.isWorker) {
const restart = path => { if (strapi.reload.isWatching && cluster.isWorker && !strapi.reload.isReloading) { strapi.reload.isReloading = true; strapi.log.info(`File changed: ${path}`); strapi.reload(); } }
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); }