Node.js Stream Timer Recursion

孤者浪人 提交于 2019-12-24 11:27:30

问题


I need to read from a stream when my application goes live, but at the moment, i'm just reading from a normal log file (60000+ JSON documents inside).

I will need to read the data received from the last minute(not implemented, since I don't have acess to the stream and can't figure out how to do it), process the data, and ask for more next minute. Any packages or tutorials to help? please

Now I'm using a recursion. that every minute calls the start() function, I'm using the setTimeout function but it doesn't seem right.

app.js:

function start()
{
    console.dir(new Date())
    cfg.checkDb()
    setTimeout(start, 60000);
}

start();

cfg.js:

exports.checkDb = function () {
    MongoClient.connect(url, function (err, database) {
        db = database;
        flags = db.collection('flags');
        historico = db.collection('historico');
        if (isEmpty(mobile) == true) {
            dbToMemory(init);
        }
        else {
            init();
        }
    })
}


function init() {
    fs.readFile('log.log', 'utf8', function (err, source) {
        objfile = JSON.parse(source);
        searchFilePile(objfile);
    })
}

EDIT: The stream come from a server that receives documents from another source, every document comes already in asceding order.

来源:https://stackoverflow.com/questions/32206017/node-js-stream-timer-recursion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!