pipeproc
Version:
Multi-process log processing for nodejs
45 lines (44 loc) • 1.54 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const async_1 = require("async");
function waitForProcs(activeTopics, registeredProcs, procFilter, callback) {
async_1.forever(function (next) {
let procsToCheck;
if (procFilter.length > 0) {
procsToCheck = registeredProcs.
filter(p => p.status === "active" && activeTopics[p.topic] && procFilter.indexOf(p.name) > -1);
}
else {
procsToCheck = registeredProcs.
filter(p => p.status === "active" && activeTopics[p.topic]);
}
async_1.every(procsToCheck, function (proc, nextProc) {
const currentTone = parseInt(activeTopics[proc.topic].currentTone);
let procTone;
if (proc.lastAckedRange.split("..")[1]) {
procTone = parseInt(proc.lastAckedRange.split("..")[1].split("-")[1]);
}
else {
return nextProc(undefined, false);
}
if (currentTone === procTone) {
nextProc(undefined, true);
}
else {
nextProc(undefined, false);
}
}, function (_err, allFlushed) {
if (allFlushed) {
next(new Error("stop"));
}
else {
setTimeout(function () {
next();
}, 20);
}
});
}, function () {
callback();
});
}
exports.waitForProcs = waitForProcs;
;