fix(core): update

This commit is contained in:
2019-08-22 13:20:41 +02:00
parent b39f607e63
commit 3ddb4c4c75
6 changed files with 54 additions and 20 deletions

View File

@ -1,22 +1,50 @@
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as plugins from './smartproxy.plugins';
import * as cluster from 'cluster';
class ProxyMaster {
public hostCandidates: plugins.tsclass
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public clusterChilds: any[] = [];
public smartsystem = new plugins.smartsystem.Smartsystem();
public async start() {
if (cluster.isMaster) {
console.log('ProxyMaster registered as cluster master');
console.log(`should spawn ${this.smartsystem.cpus.length} workers`);
for (const cpu of this.smartsystem.cpus) {
cluster.fork();
}
} else {
const proxyworkerMod = await import('./smartproxy.classes.proxyworker');
const proxyWorkerInstance = new proxyworkerMod.ProxyWorker();
console.log('Proxymaster registered a ProxyWorker!');
const data = new Uint8Array(Buffer.from('Hello Node.js'));
fs.writeFile('message.txt', data, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
}
}
}
const defaultProxyMaster = new ProxyMaster();
if (!cluster.isMaster) {
defaultProxyMaster.start();
}
console.log('hi');
// the following is interesting for the master process only
const proxyMasterCalls = {
terminateMaster: async () => {
process.kill(0);
},
start: async () => {
await defaultProxyMaster.start();
},
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
}
};
export type TProxyMasterCalls = typeof proxyMasterCalls;
expose (proxyMasterCalls);
console.log('Proxymaster started!');

View File

@ -15,6 +15,7 @@ export class SmartProxy {
public async start () {
this.proxyMasterFunctions = await plugins.smartspawn.spawn<TProxyMasterCalls>(new plugins.smartspawn.Worker('./smartproxy.classes.proxymaster'));
console.log('successfully spawned proxymaster');
await this.proxyMasterFunctions.start();
}
public async stop () {

View File

@ -1,6 +1,5 @@
// node native scope
import cluster from 'cluster';
import * as cluster from 'cluster';
import http from 'http';
import https from 'https';
@ -17,11 +16,13 @@ export {
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartspawn from '@pushrocks/smartspawn';
import * as smartsystem from '@pushrocks/smartsystem';
export {
smartrequest,
smartpromise,
smartspawn
smartspawn,
smartsystem,
};
// third party scope