Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting TypeError: this._longRunningTask is not a function error #3

Open
SharedMocha opened this issue Apr 22, 2018 · 1 comment
Open

Comments

@SharedMocha
Copy link

Code -
var timers = require("timers"),
http = require("http"),
___backgroundTimer;

process.on('message',function(msg){
console.log("Started 2");

this._longRunningTask = function(data){
    var finalArray = [];
    console.log("Started 3");
    for(var url in data){
        //TODO do something here to create the 'result'
        finalArray.push("result");
        console.log("Started 4");

    }

    //Send the results back to index.js
    if(finalArray != []){
        var data = {
            "error":null,
            "content":finalArray
        };

        try{
            console.log("Started 3.1");
            console.log("datadatadata ",data)
            process.send(data);
        }
        catch(err){
            console.log("retriever.js: problem with process.send() " + err.message + ", " + err.stack);
        }
    }
    else{
        console.log("retriever.js: no data processed");
    }
};

this._startTimer = function(){
    var count = 0;
    console.log("Started 33.1");
    ___backgroundTimer = timers.setInterval(function(){
        console.log("Started 33.2");

        try{
            var date = new Date();
            console.log("retriever.js: datetime tick: " + date.toUTCString());
            this._longRunningTask(msg.content);
        }
        catch(err){
            count++;
            if(count == 3){
                console.log("retriever.js: shutdown timer...too many errors. " + err.message);
                clearInterval(___backgroundTimer);
                process.disconnect();
            }
            else{
                console.log("retriever.js error: " + err.message + "\n" + err.stack);
            }
        }
    },msg.interval);
}

this._init = function(){
    if(msg.content != null || msg.content != "" && msg.start == true){
        this._startTimer();
        console.log("msg.contentmsg.content"+msg.content);
        console.log("Started 33");

    }
    else{
        console.log("retriever.js: content empty. Unable to start timer.");
        console.log("Started 44")
    }
}.bind(this)()

})

process.on('uncaughtException',function(err){
console.log("retriever.js: " + err.message + "\n" + err.stack + "\n Stopping background timer");
clearInterval(___backgroundTimer);
})

@andygup
Copy link
Owner

andygup commented Apr 23, 2018

I'm not surprised, this code was built for a 0.x version of node.

My initial guess is you have to declare _longRunningTask , _startTimer and _init as a private variables first up at the top of the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants