fix(core): update

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

18
package-lock.json generated
View File

@ -266,9 +266,9 @@
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ==" "integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
}, },
"@pushrocks/smartrequest": { "@pushrocks/smartrequest": {
"version": "1.1.20", "version": "1.1.23",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.20.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.23.tgz",
"integrity": "sha512-3qOrxZT9+Fhr4GD/dFH+xDHYuSUTStbJl6/jNyh6W0d1L64zH2wfuG8MwlHc3CUHFXPaGauwK+4LQ91JEUx8TQ==", "integrity": "sha512-Hws3YfzIE0b/E3aTkSugLskKWBq7e8HDXEN+RlRyTFONxW/XONKJFTw4mp3jk+puWpYGDoOTcP+Ua4jd19z9pA==",
"requires": { "requires": {
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@types/form-data": "^2.2.1", "@types/form-data": "^2.2.1",
@ -330,9 +330,9 @@
} }
}, },
"@pushrocks/smartsystem": { "@pushrocks/smartsystem": {
"version": "2.0.6", "version": "2.0.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsystem/-/smartsystem-2.0.6.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsystem/-/smartsystem-2.0.7.tgz",
"integrity": "sha512-8gDFJ2XWcTXdas10qEwqU9spNfA6WNYr8f2z8ry5EW2GP/Ja7G7Xjif9R9VTeRyJiE9eNTWWwFCOxXomAl5qbQ==", "integrity": "sha512-YwRmwfFZGJCsy4xSW6HmUfWXiHgbBdsbuwVjYJ/fb2pQn4aYp2W2FL0S6gA4pofryQVkaUcxEjFEKTpfNjM1dA==",
"requires": { "requires": {
"@pushrocks/lik": "^3.0.10", "@pushrocks/lik": "^3.0.10",
"@pushrocks/smartenv": "^4.0.7", "@pushrocks/smartenv": "^4.0.7",
@ -365,9 +365,9 @@
} }
}, },
"@tsclass/tsclass": { "@tsclass/tsclass": {
"version": "2.0.4", "version": "2.0.5",
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-2.0.4.tgz", "resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-2.0.5.tgz",
"integrity": "sha512-wNn0V2gqx9CD/RNgeG2zbJEM2gvyN79J87m0DtXTlezlqf2elaK9b5wY0iooemyHpu8SsWhNYaedNylW4Kk9hQ==" "integrity": "sha512-C+XTgdnpwtZYufz50qh04NyuIMFQSQI2606B3mzKUuVEhPXeoo4u8TN/NHzoHQHKL2JxH/RO23i3jXtV8V6mzg=="
}, },
"@types/chai": { "@types/chai": {
"version": "4.2.0", "version": "4.2.0",

View File

@ -23,10 +23,10 @@
"dependencies": { "dependencies": {
"@pushrocks/smartnetwork": "^1.1.6", "@pushrocks/smartnetwork": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.20", "@pushrocks/smartrequest": "^1.1.23",
"@pushrocks/smartspawn": "^2.0.8", "@pushrocks/smartspawn": "^2.0.8",
"@pushrocks/smartsystem": "^2.0.6", "@pushrocks/smartsystem": "^2.0.7",
"@tsclass/tsclass": "^2.0.4", "@tsclass/tsclass": "^2.0.5",
"@types/ws": "^6.0.2", "@types/ws": "^6.0.2",
"ws": "^7.1.2" "ws": "^7.1.2"
}, },

View File

@ -11,6 +11,10 @@ tap.test('should start the testproxy', async () => {
await testProxy.start(); await testProxy.start();
}); });
tap.test('should wait for 5 seconds', async (tools) => {
await tools.delayFor(5000);
});
tap.test('should close the testproxy', async () => { tap.test('should close the testproxy', async () => {
await testProxy.stop(); await testProxy.stop();
}); });

View File

@ -1,22 +1,50 @@
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn'; import { expose } from '@pushrocks/smartspawn';
import * as plugins from './smartproxy.plugins';
import * as cluster from 'cluster';
class ProxyMaster { class ProxyMaster {
public hostCandidates: plugins.tsclass public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public clusterChilds: any[] = []; 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(); const defaultProxyMaster = new ProxyMaster();
if (!cluster.isMaster) {
defaultProxyMaster.start();
}
console.log('hi');
// the following is interesting for the master process only
const proxyMasterCalls = { const proxyMasterCalls = {
terminateMaster: async () => { terminateMaster: async () => {
process.kill(0); process.kill(0);
}, },
start: async () => {
await defaultProxyMaster.start();
},
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
}
}; };
export type TProxyMasterCalls = typeof proxyMasterCalls; export type TProxyMasterCalls = typeof proxyMasterCalls;
expose (proxyMasterCalls); expose (proxyMasterCalls);
console.log('Proxymaster started!');

View File

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

View File

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