简体   繁体   English

仅将worker dyno部署到heroku(用于firebase-queue)

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

I want to deploy a NodeJS server on a worker-only dyno on heroku. 我想在heroku上的仅限worker的dyno上部署NodeJS服务器。 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. 我的服务器不需要提供文件或API。 What is the correct way to deploy to Heroku? 部署到Heroku的正确方法是什么? Specifically, what is the correct way to deploy only a firebase-queue implementation to Heroku? 具体来说,只将firebase队列实现部署到Heroku的正确方法是什么?

My server is dedicated to process work from a queue. 我的服务器专门用于处理队列中的工作。 It monitors a Firebase location and reacts on changes. 它监控Firebase位置并对更改做出反应。 Specifically, its a firebase-queue implementation, almost an exact copy of my-queue-worker.js as given in the guide 具体来说,它是一个firebase-queue实现,几乎是指南中给出的my-queue-worker.js的精确副本

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

The first important part, as stated by Yoni, is to tell Heroku that you only need a background worker and not a web worker: 如Yoni所述,第一个重要的部分是告诉Heroku你只需要一个后台工作者而不是一个网络工作者:

worker: node <path_to_your_worker>

The second important part is: Heroku will launch a web dyno by default. 第二个重要部分是:默认情况下Heroku将启动web dyno。 This causes the application to crash if your application does not bind to the port on which web traffic is received. 如果您的应用程序未绑定到接收Web流量的端口,则会导致应用程序崩溃。 To disable the web dyno and prevent the crash, run the following commands from the commandline in your directory: 要禁用Web dyno并防止崩溃,请从目录中的命令行运行以下命令:

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

This should fix the problem! 这应该解决问题!

It looks like your Procfile contains a "web" process type. 看起来您的Procfile包含“Web”流程类型。 Your Procfile should look something like this: 你的Procfile应该是这样的:

worker: node <path_to_your_worker>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM