node-resque heroku deployment Error

时间:2017-12-18 06:52:53

标签: node.js heroku redis resque

I'm trying to deploy my node application on Heroku, and on the server, I'm using node-resque to queue external api calls every 5 seconds. So I'm utilizing node-resque queue and workers, when I am trying to connect the worker and the queue im getting an ECONNREFUSED error trying to connect to 127.0.0.1:6379, which I don't know why and where that is happening. So the initialize function gets called when server starts

  this.initialize = function() {
    var client = redis.createClient(process.env.REDIS_URL);
    client.on('connect', function() {
      console.log(`Redis client running at ${process.env.REDIS_URL}`);
    })

    var queue = new NR.queue({connection: {redis:client}}, this.jobs);
      queue.on('error', function(error){
        console.log("Setting Timeout");
        setTimeout(function(){worker.start();}, 10000);
      });
      queue.connect(function(){
        console.log("Queue Connected")
      });

      var worker = new NR.worker({connection: client, queues: ['Api']}, this.jobs);
      worker.connect(function() {
      worker.workerCleanup(); // optional: cleanup any previous improperly shutdown workers on this host
      worker.start();
    });

    worker.on('start', function(){ console.log("worker started"); });
    worker.on('end', function(){ console.log("worker ended"); }); 
    worker.on('success', function(queue, job, result){
      console.log("job success " + queue + " " + " >> " + JSON.stringify(result));
      //send the result to the client
      io.emit('message', result);
    });
    worker.on('error', (error, queue, job) => { console.log(`error ${queue} ${JSON.stringify(job)}  >> ${error}`) })

    setInterval(function() {
        console.log("Calling the APIs");
        queue.length("api", function(error, num){console.log("Current Jobs in the Queue: " + num)})
        queue.enqueue('Api', "callApi", ["bittrex"]);
        queue.enqueue('Api', "callApi", ["liqui"]);
        queue.enqueue('Api', "callApi", ["bitfinex"]);
      }, 5000)
  }

The output is

Redis client running at redis://h:pcec8cc1229d465e0714640989f17478c46a3e9a14ce6fd63e4de9e9446ce06bb@ec2-34-206-75-227.compute-1.amazonaws.com:45889
2017-12-18T06:47:38.425558+00:00 app[web.1]: error null {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":6379}  >> null
2017-12-18T06:47:38.434139+00:00 app[web.1]: Queue Connected

Where would this error coming from? all the env variables are set correctly

0 个答案:

没有答案