Coder Social home page Coder Social logo

Comments (8)

navihtot avatar navihtot commented on June 2, 2024

Doing this for now:

                    setTimeout(function() { //sleep for graylog to get last messages
                        callback(null);
                    }, 10);

from node-graylog2.

ronkorving avatar ronkorving commented on June 2, 2024

How does your script finish? Do you call process.exit()?

from node-graylog2.

navihtot avatar navihtot commented on June 2, 2024

Hmm... not really sure. my code runs on AWS Lambda and I create a handler function which is then runned. Don't really now how they implemented it. If it helps function definition looks like this:

exports.handler = function(event, context, callback)

more docs: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html

from node-graylog2.

ronkorving avatar ronkorving commented on June 2, 2024

Can you show me a more complete example of what you're running?

from node-graylog2.

ronkorving avatar ronkorving commented on June 2, 2024

I do think I understand the reason though. Our log functions don't have callback arguments, but they do asynchronous work. If you bail out (in your case, calling your callback which may kill a process in that tick) there are 2 things that won't have had a chance to complete: gzip compressing of your log message, UDP-send of your message.

This is a fundamental issue in this module. We need to work on this.

from node-graylog2.

navihtot avatar navihtot commented on June 2, 2024

Well really nothing special. Here is my log.write function from log module:

module.exports.write = function (title, message) {
    if (typeof message === 'undefined') {
        message = "";
    }
    if ( process.env.NODE_ENV !== 'test' ) {
        console.log(module.exports.timestamp()+'\t'+title+'\t'+message);
        if (message!=="") {
            if (title=='Error') logger.error(message, message);
            else if (title=='Warning') logger.warning(message, message);
            else if (title=='Info') logger.info(message, message);
            else logger.error(title, message);
        }

    }
}

and my main program function:

/**
 * Main event handler for Lambda
 *
 * @param {Object} event AWS Lambda event
 * @param {Object} context AWS Lambda context
 * @callback callback function(err)
 *      @param {Error} err
 */
exports.handler = function(event, context, callback) {
    var operation = event.operation;
    delete event.operation;
    if (operation) {
        log.write('Info', 'Operation ' + operation +' requested ');
    }
    //create tmp folder for this lambda session
    fs.createFolderLocal('/tmp/'+common.getGuid());    

    switch (operation) {
        case 'transform':                
            exports.transform(event,context,  function (err) {
                if (err) context.fail(err);
                else {
                    setTimeout(function() { //sleep for graylog to get last messages
                        callback(null);
                    }, 10);
                    //context.done();
                }
            });
            break;
        default:
            context.fail(new Error('Unrecognized operation "' + operation + '"'));
    }
};

trough the rest of the code i just call log.write.
But yeah i suppose the problem is that lib functions should have async and sync way of calling (with callback or without) like its a common style with node.js

from node-graylog2.

ronkorving avatar ronkorving commented on June 2, 2024

There is no sync way to call functions that do UDP, but we need to allow callbacks to wait for gzipping and sending to complete (although iirc the callback on UDP sends is really a callback post-DNS-resolve).

from node-graylog2.

Fl4m3Ph03n1x avatar Fl4m3Ph03n1x commented on June 2, 2024

Hello,

I have this exact issue on my code right now. I need to wait for the logs to finish processing, but my app exits before that.

I see you are working on a new implementation. Is there any ETA?
Will it be backwards compatible?

from node-graylog2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.