-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.visual.server.js
66 lines (59 loc) · 1.52 KB
/
test.visual.server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Redux-Cluster Test
* (c) 2018 by Siarhei Dudko.
*
* standart test, include test Socket IPC and TCP (remote) server
* LICENSE MIT
*/
"use strict"
var ReduxCluster = require('redux-cluster'),
Cluster = require('cluster'),
Lodash = require('lodash'),
Http = require('http');
var Test = ReduxCluster.createStore(editProcessStorage);
require('./index.js').server(Test);
if(Cluster.isMaster){
let _server = new Http.createServer(undefined).setTimeout(30000).listen(8888, "0.0.0.0");
Test.createWSServer({server: _server, logins:{test2:'123456'}});
}
function editProcessStorage(state = {version:''}, action){
try {
switch (action.type){
case 'TASK':
var state_new = Lodash.clone(state);
state_new.version = action.payload.version;
return state_new;
break;
default:
break;
}
} catch(e){
}
var state_new = Lodash.clone(state);
return state_new;
}
Test.subscribe(function(){
if(Cluster.isMaster){
var name = 'm';
} else {
var name = Cluster.worker.id;
}
console.log(' S1 | ' + name + ' | ' + JSON.stringify(Test.getState()));
});
if(Cluster.isMaster){
for(var i=0; i < 2; i++){
//setTimeout(function(){Cluster.fork();}, i*10000);
}
Test.dispatch({type:'TASK', payload: {version:'OneMasterTest0'}});
var i = 0;
setInterval(function(){
Test.dispatch({type:'TASK', payload: {version:'OneMasterTest'+i}});
i++;
}, 1900);
} else {
var i = 0;
setInterval(function(){
Test.dispatch({type:'TASK', payload: {version:'OneWorkerTest'+i}});;
i++;
}, 3100+(Cluster.worker.id*3600), i);
}