Handling Requests multimessage
This commit is contained in:
@@ -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);
|
||||
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);
|
||||
}
|
||||
}).catch(err=>{
|
||||
logger.log("error","Sending Request to Service: " + err)
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
1
casRpsLogExtractor/casRpsLogExtractor.maxPKey.dat
Normal file
1
casRpsLogExtractor/casRpsLogExtractor.maxPKey.dat
Normal file
@@ -0,0 +1 @@
|
||||
0010000000a87kj9
|
||||
@@ -27,13 +27,17 @@ const server = micro(async (req, res) => {
|
||||
const js = await json(req);
|
||||
|
||||
try {
|
||||
inputLine = JSON.parse(js);
|
||||
allInputLines = JSON.parse(js);
|
||||
send(res, 200, "OK");
|
||||
} catch (ex) {
|
||||
logger.log("error", "Input not in JSON format:" + line);
|
||||
logger.log("error", "Input not in JSON format:" + js);
|
||||
send(res, 401, "Input not in JSON Format");
|
||||
}
|
||||
|
||||
let isWhiteListed = ruleEngine.processData(inputLine);
|
||||
let miniInput = jsonminify(JSON.stringify(inputLine));
|
||||
for(i=0;i<allInputLines.length;i++){
|
||||
let theInputLine=allInputLines[i];
|
||||
let isWhiteListed = ruleEngine.processData(theInputLine);
|
||||
let miniInput = jsonminify(JSON.stringify(theInputLine));
|
||||
let now = Date();
|
||||
if (isWhiteListed) {
|
||||
logger.log("debug", "Not Whitelisted: " + miniInput);
|
||||
@@ -42,8 +46,8 @@ const server = micro(async (req, res) => {
|
||||
logger.log("info", "Not Whitelisted: " + miniInput);
|
||||
fs.appendFileSync("./log/issues.log", miniInput + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
send(res, 200, "OK");
|
||||
});
|
||||
|
||||
server.listen(2222);
|
||||
Reference in New Issue
Block a user