Intro
Project Apollo is a simple framework to write a Master-Worker NodeJS service.
Install
$ npm i apollo-service
Usage
- file master.js
'use strict' const path = const Apollo } = // project name name: 'TestObject' // verbose mode develop: true // how long we wait to fork again when worker is down reforkWaitting: 2000 // where to find worker's file appPath: path // define workers workers: // name test: // fork args args: 'test' 'good' // workdir cwd: './' // fork count fork: 3 { this } { this } /** @see https://nodejs.org/docs/latest-v8.x/api/process.html#process_process_events */ processEvents: {} /** @see https://nodejs.org/docs/latest-v8.x/api/cluster.html#cluster_event_disconnect_1 */ masterEvents: {} /** @see https://nodejs.org/docs/latest-v8.x/api/cluster.html#cluster_class_worker */ workerEvents: {}
- file workers/test.js
'use strict' const ApolloWorker = // set name name: `Worker pid=` // verbose mode develop: true // run things async async { this await ApolloWorker this while true await ApolloWorker let i = if i > 98 this thisprocess else this } // you can bind process event like this processEvents: // this will run like `process.on('message', () => {})` { this // will print like 'Worker pid=2 receive message: hello world!' when receive a message from pipe } // simply bind signal signal: { // act like `process.exit(1)` this }