AREX: tak jsem dosel k tomu, ze to dela ta mapa (visjs) - stale jsem nevypnul fyziku a dokud se body neustali, tak to pocita jako vztekle. jakmile zazoomuju tak aby byly videt 2-3 body (asi to nejni tolik vytizene), violations zmizi ...
ale, mam jeste jeden dotaz - v nodejs si vytvarim child procesy forkem. napr. pro mysql operace, aby mi to nezdrzovalo hlavni proces. doposud vse ok - select, insert, update, retez nekolika udalosti select a potom insert / update - vse ok. ale nyni jsem narazil - child process mi v logu pise, ze odesila data do hlavniho procesu (jednou) a hlavni proces zarve, ze data obdrzel nekolikrat - tedy jakoby se on event volal vicekrat (?) nedelam nejakou zasadni blbost ? nebo to delam cele spatne ?
worker_mysql: Found 1 subnet in MYSQL.
worker_mysql: sending to main process {"err":false,"sqlAction":"select","sqlTable":"subnet","rows":[{"id_subnet":1,"prefixSize":24,"network":"10.133.36.0","purpose":0,"id_node":-1}]}
^^^
child process hlasi 1x odeslani
....ale hlavni proces nekolikrat prijeti....
mod_subnets: received from SQL worker {"err":false,"sqlAction":"select","sqlTable":"subnet","rows":[{"id_subnet":1,"prefixSize":24,"network":"10.133.36.0","purpose":0,"id_node":-1}]}
mod_subnets: subnet 10.133.36.0 exists in database
mod_subnets: received from SQL worker {"err":false,"sqlAction":"select","sqlTable":"subnet","rows":[{"id_subnet":1,"prefixSize":24,"network":"10.133.36.0","purpose":0,"id_node":-1}]}
mod_subnets: subnet 10.133.36.0 exists in database
mod_subnets: received from SQL worker {"err":false,"sqlAction":"select","sqlTable":"subnet","rows":[{"id_subnet":1,"prefixSize":24,"network":"10.133.36.0","purpose":0,"id_node":-1}]}
mod_subnets: subnet 10.133.36.0 exists in database
mod_subnets: received from SQL worker {"err":false,"sqlAction":"select","sqlTable":"subnet","rows":[{"id_subnet":1,"prefixSize":24,"network":"10.133.36.0","purpose":0,"id_node":-1}]}
mod_subnets: subnet 10.133.36.0 exists in database
hlavni proces vola child takto
global.sql.worker.send(request);
global.sql.worker.once('message', function(resp) {
console.log(_Fname+': received from SQL worker '+JSON.stringify(resp));
if (resp.err == false && resp.sqlTable == 'subnet' && resp.sqlAction == 'select') {
if (resp.rows.length === 0) {
console.log(_Fname+': subnet does not exist in database');
var insertRequest = [{sqlAction: 'insert', sqlTable: 'subnet', network: subnet.networkAddress, prefixSize: subnet.subnetMaskLength, purpose: purpose, id_node: router }];
global.sql.worker.send(insertRequest);
return
} else {
console.log(_Fname+': subnet '+resp.rows[0].network+' exists in database');
return
}
}
});
global.sql.worker.once('message', function(resp) {
if (resp.err == false && resp.sqlTable == 'subnet' && resp.sqlAction == 'insert') {
console.log(_Fname+': subnet inserted with ID '+resp.insertId);
return
}
});
--------------------------------------------------
a child odpovida takto
process.on('message', function(data) {
console.log('worker_mysql: rececived data '+JSON.stringify(data));
var table = data[0].sqlTable;
var action = data[0].sqlAction;
delete data[0].sqlTable;
delete data[0].sqlAction;
switch(action) {
case "select":
select(table,data,function(err,table,rows) {
if (err) {
var result = { err: true, sqlAction: action, sqlTable: table, rows: null };
} else {
var result = { err: false, sqlAction: action, sqlTable: table, rows: rows };
}
console.log('worker_mysql: sending to main process '+JSON.stringify(result)+'');
process.send(result);
return
});
break;
case "insert":
insert(table,data,function(err,insertId,dataOut) {
if (err) {
var result = { err: true, sqlAction: action, sqlTable: table, insertId: null, object: null };
} else {
var result = { err: false, sqlAction: action, sqlTable: table, insertId: insertId, object: dataOut };
}
console.log('worker_mysql: sending to main process '+JSON.stringify(result)+'');
process.send(result);
return
});
break;
case "update":
break;
default:
break;
}
nevim proc, ale NYX nejak zkomolil ten zdrojak :-) snad tomu je rozumnet...