4

I want to deploy a NodeJS server on a worker-only dyno on heroku. I've tried several approaches but I always get the error:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

My server does not need to serve files or an API. What is the correct way to deploy to Heroku? Specifically, what is the correct way to deploy only a firebase-queue implementation to Heroku?

My server is dedicated to process work from a queue. It monitors a Firebase location and reacts on changes. Specifically, its a firebase-queue implementation, almost an exact copy of my-queue-worker.js as given in the guide

var Queue = require('firebase-queue');
var firebase = require('firebase');

firebase.initializeApp({
  serviceAccount: '{projectId: 'xx', clientEmail: 'yy', privateKey: 'zz'}',
  databaseURL: '<your-database-url>'
});

var ref = firebase.database().ref('queue');
var queue = new Queue(ref, function(data, progress, resolve, reject) {
  // Read and process task data
  console.log(data);

 // Do some work
 progress(50);

 // Finish the task asynchronously
  setTimeout(function() {
  resolve();
  }, 1000);
});
Tielman Nieuwoudt
  • 903
  • 1
  • 12
  • 24

2 Answers2

6

The first important part, as stated by Yoni, is to tell Heroku that you only need a background worker and not a web worker:

worker: node <path_to_your_worker>

The second important part is: Heroku will launch a web dyno by default. This causes the application to crash if your application does not bind to the port on which web traffic is received. To disable the web dyno and prevent the crash, run the following commands from the commandline in your directory:

$ heroku ps:scale web=0 worker=1
$ heroku ps:restart

This should fix the problem!

Tielman Nieuwoudt
  • 903
  • 1
  • 12
  • 24
2

It looks like your Procfile contains a "web" process type. Your Procfile should look something like this:

worker: node <path_to_your_worker>
Yoni Rabinovitch
  • 5,171
  • 1
  • 23
  • 34
  • Thanks, I did try it before. Checked again now. Turns out Heroku automatically launches a web dyno. When the port is not binded to, it automatically scales the web dynos to zero. Thanks for helping out. – Tielman Nieuwoudt Jul 13 '16 at 05:53