error handling in dbExtractor
This commit is contained in:
@@ -58,51 +58,55 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.connect(config.sqlConfig, err => {
|
try {
|
||||||
if (err) {
|
sql.connect(config.sqlConfig, err => {
|
||||||
logger.log("error", "Connecting to DB: " + err);
|
if (err) {
|
||||||
}
|
logger.log("error", "Connecting to DB: " + err);
|
||||||
const sqlRequest = new sql.Request();
|
}
|
||||||
sqlRequest.stream = true;
|
const sqlRequest = new sql.Request();
|
||||||
|
sqlRequest.stream = true;
|
||||||
|
|
||||||
function runNextPoll(){
|
function runNextPoll(){
|
||||||
sqlRequest.query("select top " + maxResultsPerMessage + " * from rpslog where pkey > '" + maxPKey + "' order by pkey");
|
sqlRequest.query("select top " + maxResultsPerMessage + " * from rpslog where pkey > '" + maxPKey + "' order by pkey");
|
||||||
}
|
}
|
||||||
|
|
||||||
runNextPoll();
|
runNextPoll();
|
||||||
|
|
||||||
sqlRequest.on('row', row => {
|
sqlRequest.on('row', row => {
|
||||||
outData = { sourceTag: config.sourceTag, processingType: config.processingType, data: row };
|
outData = { sourceTag: config.sourceTag, processingType: config.processingType, data: row };
|
||||||
process.stdout.write("#");
|
process.stdout.write("#");
|
||||||
request.json = true;
|
request.json = true;
|
||||||
|
|
||||||
logger.log('debug', "adding row to array:" + JSON.stringify(outData));
|
logger.log('debug', "adding row to array:" + JSON.stringify(outData));
|
||||||
allRows.push(outData);
|
allRows.push(outData);
|
||||||
|
|
||||||
if (row.PKey > maxPKeyUnsent) {
|
if (row.PKey > maxPKeyUnsent) {
|
||||||
maxPKeyUnsent = row.PKey;
|
maxPKeyUnsent = row.PKey;
|
||||||
logger.log("debug", "MaxPKeyUnsent Written: " + maxPKeyUnsent);
|
logger.log("debug", "MaxPKeyUnsent Written: " + maxPKeyUnsent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sqlRequest.on('done', result => {
|
sqlRequest.on('done', result => {
|
||||||
clearInterval(theInterval);
|
clearInterval(theInterval);
|
||||||
if (allRows.length>0){
|
if (allRows.length>0){
|
||||||
request({ method: 'POST', uri: config.serverURI, body: JSON.stringify(allRows), json: true }).then(_ => {
|
request({ method: 'POST', uri: config.serverURI, body: JSON.stringify(allRows), json: true }).then(_ => {
|
||||||
// count up the maxPKey only when the request was successful...
|
// count up the maxPKey only when the request was successful...
|
||||||
maxPKey=maxPKeyUnsent;
|
maxPKey=maxPKeyUnsent;
|
||||||
fs.writeFileSync("DBExtractor.maxPKey.dat", maxPKey);
|
fs.writeFileSync("DBExtractor.maxPKey.dat", maxPKey);
|
||||||
}).catch(err=>{
|
}).catch(err=>{
|
||||||
logger.log("error","Sending Request to Service: " + err)
|
logger.log("error","Sending Request to Service: " + err)
|
||||||
}).finally(_=>{
|
}).finally(_=>{
|
||||||
runNextPoll();
|
runNextPoll();
|
||||||
});
|
});
|
||||||
process.stdout.write(">" + allRows.length + ">");
|
process.stdout.write(">" + allRows.length + ">");
|
||||||
} else {
|
} else {
|
||||||
theInterval = setInterval(runNextPoll, config.pollIntervalIdle);
|
theInterval = setInterval(runNextPoll, config.pollIntervalIdle);
|
||||||
process.stdout.write(".");
|
process.stdout.write(".");
|
||||||
}
|
}
|
||||||
allRows=[];
|
allRows=[];
|
||||||
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
} catch (ex) {
|
||||||
|
logger.log("error", `Fatal error occured: ${ex}`);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user