flexbiz-server 12.5.12 → 12.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "flexbiz-server",
3
3
  "main": "./server/app.js",
4
4
  "description": "Flexible Server",
5
- "version": "12.5.12",
5
+ "version": "12.5.13",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -7,127 +7,127 @@ const Server = require('../app');
7
7
  const utils = require("../libs/utils");
8
8
  const handlers = require('../controllers/handlers');
9
9
  const handleData =async (msg)=>{
10
- try{
11
- let ctrl = global.controllers[msg.module.trim()];
12
- if(ctrl){
13
- if(msg.req && msg.req.handler){
14
- const action = handlers[msg.req.handler]
15
- if(action){
16
- try {
17
- action(ctrl,msg.req,async (error,result)=>{
18
- try{
19
- if(result){
20
- if(result.toObject){
21
- result = utils.convertObjectIdsToStrings(result.toObject());
22
- }
23
- if(_.isArray(result)){
24
- result = result.map(r=>{
25
- if(r.toObject){
26
- return utils.convertObjectIdsToStrings(r.toObject());
27
- }else{
28
- return r;
29
- }
30
- })
31
- }
32
- //Chỉ re_parse nếu không phải là buffer
33
- if(!Buffer.isBuffer(result)){
34
- result = JSON.parse(JSON.stringify(result));
35
- }
36
- }
37
- parentPort.postMessage({error:error?.message||error?.error||error,result,id_task:msg.id_task});
38
- }catch(e){
39
- console.error("[inputWorker] Error post mesage to parent processs",e,result);
40
- parentPort.postMessage({error:e.message,id_task:msg.id_task});
41
- }
42
-
43
- })
44
- } catch (e) {
45
- parentPort.postMessage({error:e.message,id_task:msg.id_task});
46
- }
47
- }else{
48
- console.error("[inputWorker] not found handler",msg.req.handler,". Các handler có giá trị:",Object.keys(handlers).join(","));
49
- parentPort.postMessage({error:"Không tìm thấy handler: " + msg.req.handler,id_task:msg.id_task});
50
- }
51
- }else{
52
- parentPort.postMessage({error:"Không tìm thấy req hoặc tên handler",id_task:msg.id_task});
53
- }
54
- }else{
55
- parentPort.postMessage({error:"Không tìm thấy module " + msg.module,id_task:msg.id_task});
56
- }
57
- }catch(e){
58
- parentPort.postMessage({error:e,id_task:msg.id_task});
59
- }
10
+ try{
11
+ let ctrl = global.controllers[msg.module.trim()];
12
+ if(ctrl){
13
+ if(msg.req && msg.req.handler){
14
+ const action = handlers[msg.req.handler]
15
+ if(action){
16
+ try {
17
+ action(ctrl,msg.req,async (error,result)=>{
18
+ try{
19
+ if(result){
20
+ if(result.toObject){
21
+ result = utils.convertObjectIdsToStrings(result.toObject());
22
+ }
23
+ if(_.isArray(result)){
24
+ result = result.map(r=>{
25
+ if(r.toObject){
26
+ return utils.convertObjectIdsToStrings(r.toObject());
27
+ }else{
28
+ return r;
29
+ }
30
+ })
31
+ }
32
+ //Chỉ re_parse nếu không phải là buffer
33
+ if(!result?.data || !Buffer.isBuffer(result?.data)){
34
+ result = JSON.parse(JSON.stringify(result));
35
+ }
36
+ }
37
+ parentPort.postMessage({error:error?.message||error?.error||error,result,id_task:msg.id_task});
38
+ }catch(e){
39
+ console.error("[inputWorker] Error post mesage to parent processs",e,result);
40
+ parentPort.postMessage({error:e.message,id_task:msg.id_task});
41
+ }
42
+
43
+ })
44
+ } catch (e) {
45
+ parentPort.postMessage({error:e.message,id_task:msg.id_task});
46
+ }
47
+ }else{
48
+ console.error("[inputWorker] not found handler",msg.req.handler,". Các handler có giá trị:",Object.keys(handlers).join(","));
49
+ parentPort.postMessage({error:"Không tìm thấy handler: " + msg.req.handler,id_task:msg.id_task});
50
+ }
51
+ }else{
52
+ parentPort.postMessage({error:"Không tìm thấy req hoặc tên handler",id_task:msg.id_task});
53
+ }
54
+ }else{
55
+ parentPort.postMessage({error:"Không tìm thấy module " + msg.module,id_task:msg.id_task});
56
+ }
57
+ }catch(e){
58
+ parentPort.postMessage({error:e,id_task:msg.id_task});
59
+ }
60
60
  }
61
61
  const handleTask = (msg)=>{
62
- if(_.isString(msg)){
63
- try{
64
- msg = JSON.parse(msg);
65
- }catch(e){
66
- //delete msg.configs;
67
- console.error(e);
68
- parentPort.postMessage({
69
- error: "msg is not valid"
70
- });
71
- return;
72
- }
73
- }
74
- //
75
- msg = msg ||{};
76
- msg.user = msg.user || (msg.req||{}).user;
77
- if(!msg.load && (!msg.user || !msg.module) ){
78
- parentPort.postMessage({
79
- error: "msg is not valid"
80
- });
81
- return;
82
- }
83
- if(!sv){
84
- if(msg.configs && _.isString(msg.configs)){
85
- try{
86
- msg.configs = JSON.parse(msg.configs);
87
- }catch(e){
88
- delete msg.configs;
89
- console.info(e);
90
- }
91
- }
92
- const configs = msg.configs || require("../configs");
93
- configs.use_ssl = false;
94
- configs.createIndexes = false;
95
- configs.port = 10000 + configs.port;
96
- Server(app,{configs,createServer:false,start_report_pool:false,start_import_data_pool:false,start_abci_handler:false,lite:true},()=>{
97
- console.log("🔥 Input worker started:",msg.id_worker);
98
- sv = true;
99
- if(msg.load){
100
- return parentPort.postMessage({rs:"ready",id_task:msg.id_task});
101
- }
102
- handleData(msg);
103
- });
104
- }else{
105
- handleData(msg)
106
- }
62
+ if(_.isString(msg)){
63
+ try{
64
+ msg = JSON.parse(msg);
65
+ }catch(e){
66
+ //delete msg.configs;
67
+ console.error(e);
68
+ parentPort.postMessage({
69
+ error: "msg is not valid"
70
+ });
71
+ return;
72
+ }
73
+ }
74
+ //
75
+ msg = msg ||{};
76
+ msg.user = msg.user || (msg.req||{}).user;
77
+ if(!msg.load && (!msg.user || !msg.module) ){
78
+ parentPort.postMessage({
79
+ error: "msg is not valid"
80
+ });
81
+ return;
82
+ }
83
+ if(!sv){
84
+ if(msg.configs && _.isString(msg.configs)){
85
+ try{
86
+ msg.configs = JSON.parse(msg.configs);
87
+ }catch(e){
88
+ delete msg.configs;
89
+ console.info(e);
90
+ }
91
+ }
92
+ const configs = msg.configs || require("../configs");
93
+ configs.use_ssl = false;
94
+ configs.createIndexes = false;
95
+ configs.port = 10000 + configs.port;
96
+ Server(app,{configs,createServer:false,start_report_pool:false,start_import_data_pool:false,start_abci_handler:false,lite:true},()=>{
97
+ console.log("🔥 Input worker started:",msg.id_worker);
98
+ sv = true;
99
+ if(msg.load){
100
+ return parentPort.postMessage({rs:"ready",id_task:msg.id_task});
101
+ }
102
+ handleData(msg);
103
+ });
104
+ }else{
105
+ handleData(msg)
106
+ }
107
107
  }
108
108
  let sv = false;
109
109
  parentPort.on("message", (msg)=>{
110
- handleTask(msg);
110
+ handleTask(msg);
111
111
  })
112
112
  if(workerData){
113
- (()=>{
114
- handleTask(workerData);
115
- })()
113
+ (()=>{
114
+ handleTask(workerData);
115
+ })()
116
116
  }
117
117
  //Gửi tín hiệu worker is alive
118
118
  setInterval(() => {
119
- parentPort.postMessage('pong');
119
+ parentPort.postMessage('pong');
120
120
  }, 5000);
121
121
 
122
122
 
123
123
  process.on('uncaughtException', (err) => {
124
- if (err.code === 'EPIPE') {
125
- console.error('❌ [inputworker] Caught EPIPE:', err.message);
126
- } else {
127
- console.error('❌ [inputworker] Uncaught exception:', err);
128
- }
124
+ if (err.code === 'EPIPE') {
125
+ console.error('❌ [inputworker] Caught EPIPE:', err.message);
126
+ } else {
127
+ console.error('❌ [inputworker] Uncaught exception:', err);
128
+ }
129
129
  });
130
130
 
131
131
  process.on('unhandledRejection', (reason) => {
132
- console.error('❌ [inputworker] Unhandled promise rejection:', reason);
132
+ console.error('❌ [inputworker] Unhandled promise rejection:', reason);
133
133
  });
@@ -31,8 +31,8 @@ const handleReport =async (msg)=>{
31
31
  }
32
32
  })
33
33
  }
34
- //Chỉ re_parse nếu không phải là buffer
35
- if(!Buffer.isBuffer(result)){
34
+ //Chỉ parse lại nếu không phải là buffer
35
+ if(!result?.data || !Buffer.isBuffer(result?.data)){
36
36
  result = JSON.parse(JSON.stringify(result));
37
37
  }
38
38
  }