From a1f044d9a798ad21389d0eb455ccc6cefe8ca12b Mon Sep 17 00:00:00 2001 From: Sumate Kongpui Date: Mon, 20 Aug 2018 13:36:05 +0700 Subject: [PATCH] update parallel --- ais-structure/src/config/config.js | 3 ++- ais-structure/src/modules/customer/customer.ctrl.js | 4 ++-- ais-structure/src/modules/helper/connection.js | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ ais-structure/src/modules/helper/responseMsg.js | 2 +- 4 files changed, 155 insertions(+), 22 deletions(-) diff --git a/ais-structure/src/config/config.js b/ais-structure/src/config/config.js index f024ef7..14e5eac 100644 --- a/ais-structure/src/config/config.js +++ b/ais-structure/src/config/config.js @@ -46,7 +46,8 @@ var config = { }, http_req_timeout: 120, session: 30, //minutes - Default_Timeout: 10 + Default_Timeout: 10, + Uri_length: 1000 } }; diff --git a/ais-structure/src/modules/customer/customer.ctrl.js b/ais-structure/src/modules/customer/customer.ctrl.js index ae5d5ac..a66e97d 100644 --- a/ais-structure/src/modules/customer/customer.ctrl.js +++ b/ais-structure/src/modules/customer/customer.ctrl.js @@ -19,8 +19,8 @@ exports.customer = async function (req, res, next) { var objectData = req.query; const result = await connection.requestJsonToD01(objectData,sendCmd,"GET"); if(typeof result.err === 'undefined'){ - // console.log(result.response.body); - var resultObj = JSON.parse(result.response.body); + // console.log(result.response); + var resultObj = result.response; if(resultObj.resultCode == "20000") { if(resultObj.resultData && resultObj.resultData.length>0) diff --git a/ais-structure/src/modules/helper/connection.js b/ais-structure/src/modules/helper/connection.js index f77b5ad..a5c4a73 100644 --- a/ais-structure/src/modules/helper/connection.js +++ b/ais-structure/src/modules/helper/connection.js @@ -26,36 +26,141 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) { if(params.method == "GET") { - params.url = getUrl(params); - delete params.body; - }else if(params.method == "POST") - { - params.body = JSON.stringify(params.body); - } + var genUrl = getUrl(params); + genUrl.push(genUrl[0]); + if(genUrl.length > 1) + { + // console.log("multi Send"); + var multiSend = []; + var loopData = {}; + for(var i=0;i { request(params, function (error, response, body) { @@ -63,13 +168,15 @@ function asyncRequest (params = {},cmd,node) { if (error) { // console.log("error"); + console.log("Start : "+new Date()); stats.reciveResponse(node,cmd,"Error"); resolve({ 'body' : body, 'err' : error }); } else { - // console.log("normal"); + // console.log("normal"); + console.log("End : "+new Date().toISOString()); // stats.reciveResponse(node,cmd,"Success"); resolve({ 'body' : body, @@ -82,6 +189,7 @@ function asyncRequest (params = {},cmd,node) { function getUrl(params) { + var returnData = []; var url = params.url; var fields = ""; var filter = ""; @@ -104,13 +212,37 @@ function getUrl(params) } if(filter != "") - filter = "?filter=(&"+filter+")"; + { + var maxFilterLength = cfg.Uri_length - url.length - fields.length + "?filter=(&)".length; + + if(maxFilterLength > filter.length) + { + returnData.push(url+"?filter=(&"+filter+")"+fields); + + }else + { + // while(maxFilterLength < filter.length) + // { + + // returnData.push(url+"?filter=(&"+filter+")"+fields); + // } + + } + + } + + + + + + + // console.log(url); // console.log(filter); // console.log(fields); - return url+filter+fields; + return returnData; } function getFields(fields,first) diff --git a/ais-structure/src/modules/helper/responseMsg.js b/ais-structure/src/modules/helper/responseMsg.js index 30cb709..6c43780 100644 --- a/ais-structure/src/modules/helper/responseMsg.js +++ b/ais-structure/src/modules/helper/responseMsg.js @@ -32,7 +32,7 @@ responseMsg.success = function (req,cmd,data){ resultCode : "20000", developerMessage : "Success", resultData : data.resultData, - rowCount : data.rowCount + rowCount : data.resultData.length }; stats.sendResponse(req.method,cmd,"Success"); -- libgit2 0.21.2