Handling Requests multimessage

This commit is contained in:
Joe
2019-01-07 07:51:40 -06:00
parent bdf24867f8
commit e29b4b9e86
3 changed files with 40 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
const sql = require("mssql/msnodesqlv8");
//const sql = require("mssql");
//const sql = require("mssql/msnodesqlv8");
const sql = require("mssql");
const request = require("request-promise");
const fs = require("fs");
const winston = require("winston");
@@ -25,7 +25,9 @@ const config = JSON.parse(fs.readFileSync("casRpsLogExtractor.config.json", "utf
logger.log("debug", "Config" + JSON.stringify(config))
const processingType = "casrpslog";
let maxPKey = "";
let maxPKeyUnsent = "";
let lastOutMaxPKey = "";
let allRows = [];
try {
lastOutMaxPKey = maxPKey = fs.readFileSync("casRpsLogExtractor.maxPKey.dat", "utf8");
logger.log("debug", "MaxPKey Loaded: " + maxPKey);
@@ -53,20 +55,28 @@ sql.connect(config.sqlConfig, err => {
process.stdout.write("#");
request.json = true;
logger.log('debug', "sending data:" + JSON.stringify(outData));
request({ method: 'POST', uri: config.serverURI, body: JSON.stringify(outData), json: true }).then(_ => {
// count up the maxPKey only when the request was successful...
if (row.PKey > maxPKey) {
maxPKey = row.PKey;
fs.writeFileSync("casRpsLogExtractor.maxPKey.dat", maxPKey);
logger.log("debug", "MaxPKey Written: " + maxPKey);
}
}).catch(err=>{
logger.log("error","Sending Request to Service: " + err)
});
logger.log('debug', "adding row to array:" + JSON.stringify(outData));
allRows.push(outData);
if (row.PKey > maxPKeyUnsent) {
maxPKeyUnsent = row.PKey;
logger.log("debug", "MaxPKeyUnsent Written: " + maxPKeyUnsent);
}
});
sqlRequest.on('done', result => {
if (allRows.length>0){
request({ method: 'POST', uri: config.serverURI, body: JSON.stringify(allRows), json: true }).then(_ => {
// count up the maxPKey only when the request was successful...
maxPKey=maxPKeyUnsent;
fs.writeFileSync("casRpsLogExtractor.maxPKey.dat", maxPKey);
}).catch(err=>{
logger.log("error","Sending Request to Service: " + err)
});
process.stdout.write(">" + allRows.length + ">");
allRows=[];
}
if (lastOutMaxPKey !== maxPKey) {
process.stdout.write("[" + maxPKey + "]\n");
lastOutMaxPKey = maxPKey;