Skip to content

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

Description

@SharedMocha

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);
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions