Files
logAggregator/casRpsLogExtractor.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-01-02 13:17:56 -06:00
let sql=require("mssql");
2019-01-02 14:22:10 -06:00
let request=require("request-promise");
2019-01-02 13:17:56 -06:00
//sql.trustedConnection = true;
let sqlConfig = {
user: 'casdbuser',
password:'4KcLao2016!',
server: 'ustww2063\\CCE',
database: 'CAS110',
port: 1433
}
let sourceTag="CCERpsLog";
let processingType="casrpslog";
let maxPKey="";
sql.connect(sqlConfig,err => {
console.log("JOE" , err);
2019-01-02 14:22:10 -06:00
const sqlRequest = new sql.Request();
sqlRequest.stream = true;
2019-01-02 13:17:56 -06:00
setInterval(_=>{
2019-01-02 14:22:10 -06:00
sqlRequest.query('select top 1 * from rpslog where pkey > \'' + maxPKey + '\' order by pkey');
},500)
2019-01-02 13:17:56 -06:00
2019-01-02 14:22:10 -06:00
sqlRequest.on('row',row=>{
outData={sourceTag:sourceTag,processingType:processingType,data:row};
console.log(outData);
request.json = true;
request({method:'POST',uri:'http://localhost:2222',body:JSON.stringify(outData),json:true}).then(_=>{
// count up the maxPKey only when the request was successful...
2019-01-02 13:17:56 -06:00
if (row.PKey > maxPKey) {
maxPKey=row.PKey;
}
2019-01-02 14:22:10 -06:00
});
2019-01-02 13:17:56 -06:00
});
2019-01-02 14:22:10 -06:00
sqlRequest.on('done', result=>{
2019-01-02 13:17:56 -06:00
console.log("Done");
});
})