@swenkerorg/nulla-voluptates-voluptates
A simple lib to manage multiple processes on nodejs. It makes horizontal scaling easy on multiple machines over HTTP traffic.
Installation
npm install @swenkerorg/nulla-voluptates-voluptates
Usage
import slavery from 'slaveryr-js';
let make_timeout = s =>
new Promise( resolve => {
setTimeout( () => {
resolve(s)
}, s * 1000)
})
let timeouts = [ 1, 2, 3, 4, 5, 6, 7, 8 ].reverse()
let options = {
numberOfSlaves: 9,
port: 3003,
host: 'localhost',
}
slavery(options)
.master( async master => {
await master.untilConnected();
for (let timeout of timeouts ){
let slave = await master.getIdle();
slave.run(timeout)
.then( result =>
console.log( result )
);
}
}).slave( async (parameter, slave) => {
let timeout = make_timeout(parameter);
let s = await timeout;
if( s > 7 )
return { result: `waited for ${s} seconds, 😡` }
else if( s > 5 )
return { result: `waited for ${s} seconds, 😐` }
else if( s > 2 )
return { result: `waited for ${s} seconds, 😃` }
else
return { result: `waited for ${s} seconds, 😄` }
})
});
Multiple functions
import slavery from '@swenkerorg/nulla-voluptates-voluptates';
slavery({
numberOfSlaves: 3,
port: 3003,
host: 'localhost',
}).master( async master => {
while( true ) {
let slave = await master.getIdle();
let isReady = await slave.is_done('setup');
if( !isReady )
slave.run(setup_paramters, 'setup')
else
result = slave.run(defualt_parameters)
}
}).slave( {
'setup': async (name, slave) => {
let setup = new Setup();
slave.set('setup', setup);
},
'default': async (params_for_testClassic, salve) => {
let setup = salve.get('setup');
let result = setup.run();
return result;
},
'clean up': async (param, slave) => {
slave.set('setup', null);
setup.clean();
}
})
Options
import { Server } from "socket.io";
slavery({
numberOfSlaves: 3,
port: 3003,
host: 'localhost',
timeout: 1000,
crashOnError: false,
passErrorToMaster: true,
maxTransferSize: 1e9,
io: new Server(),
heartBeat: 1000,
}).master(() => {})
.slave(() => {})
```