Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy only worker dyno to heroku (for firebase-queue)

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);
});
like image 532
Tielman Nieuwoudt Avatar asked Feb 07 '23 14:02

Tielman Nieuwoudt


1 Answers

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!

like image 158
Tielman Nieuwoudt Avatar answered Feb 12 '23 09:02

Tielman Nieuwoudt