I've got a nodejs app which runs about 40 oracle connections/queries. I'm using async to limit the asynchronous calls from the proposed solution here. My issue is the drain callback is running and completing before my function/queries complete. Any help greatly appreciated.
var queue = async.queue(runAsyncCallout, 5);
queue.concurrency = 5;
db.collection('callout').find({'active':0}).each(function(error, callout) {
queue.push(callout);
});
queue.drain = function() {
db.collection('callout_lock').update({'context': 'ALL_CALLOUTS'}, {$set: {'lock': '0'}});
db.collection('callout_lock').update({'context': 'ALL_CALLOUTS'}, {$set: {'date': time_stamp}});
console.log("All callouts done unlocking");
};
queue.concurrency = 5;
function runAsyncCallout(callout, callback) {
switch(callout.db_connect){//Grab connection profiles
case "A":
connAttrs=A;
break;
case "B":
connAttrs=B;
break;
case "C":
connAttrs=C;
break;
default:
connAttrs=D;
}
oracledb.getConnection(connAttrs, function (e, connection) {
connection.execute(callout.query, {}, {
outFormat: oracledb.OBJECT
}, function (e, result) {
//Sparing the details here, run oracle query and save to mongodb
doRelease(connection);
});
});
callback();
}