简体   繁体   English

在Heroku上使用rails sync gem与Faye和Thin在生产模式下

[英]Using rails sync gem with Faye and Thin in production mode on Heroku

I'm trying to set up the 'sync' gem to enable real time updates in my rails app. 我正在尝试设置'sync'gem以在我的rails应用程序中启用实时更新。 This uses Faye as a real time push service and thin as the webserver. 这使用Faye作为实时推送服务,并使用瘦身作为网络服务器。

I"m VERY new to this. So any advice is appreciated. 我对此非常陌生。所以任何建议都表示赞赏。

I have this working on my local server, but don't know how to get it working in production mode on heroku. 我在我的本地服务器上工作,但不知道如何让它在heroku上的生产模式下工作。 This is my setup: 这是我的设置:

In my gemfile: 在我的gemfile中:

gem 'faye'
gem 'thin', require: false
gem 'sync'

In my root folder, I have a sync.ru file 在我的根文件夹中,我有一个sync.ru文件

require "bundler/setup"
require "yaml"
require "faye"
require "sync"

Faye::WebSocket.load_adapter 'thin'

Sync.load_config(
  File.expand_path("../config/sync.yml", __FILE__),
  ENV["RAILS_ENV"] || "development"
)

run Sync.pubsub_app

In my config/sync.yml 在我的config / sync.yml中

# Faye
development:
  server: "http://localhost:9292/faye"
  adapter_javascript_url: "http://localhost:9292/faye/faye.js" 
  auth_token: DEVELOPMENT_SECRET_TOKEN
  adapter: "Faye"
  async: true

production:
  server: "http://my_app_name.com/faye"
  adapter_javascript_url: "http://localhost:9292/faye/faye.js" 
  adapter: "Faye"
  auth_token: "1b7329869f09aa98499258dfe9c377cdd2c89c05b99069176445942575348da0"
  async: true

On my local server, I simply run: 在我的本地服务器上,我只是运行:

rackup sync.ru -E production

This starts the thin web server and real time updates work in my app. 这启动了瘦Web服务器,并在我的应用程序中实时更新。

How can I get this working on Heroku? 我怎样才能在Heroku上运行?

I've tried adding the following to my procfile (no idea if this is the right thing to do) 我已经尝试将以下内容添加到我的proc文件中(不知道这是否正确)

web:  bundle exec thin -p $PORT -e $RACK_ENV -R sync.ru start

When I try and load my app, my browser displays the following text: 当我尝试加载我的应用程序时,我的浏览器显示以下文本:

Sure you're not looking for /faye ?

And my heroku log reads: 我的heroku日志写道:

app[web.1]: Starting process with command 'bundle exec thin -p 57204 -e production -R sync.ru start'
app[web.1]: Listening on 0.0.0.0:57204
app[web.1]: Maximum connections set to 1024
app[web.1]: Thin web server (v.1.6.3 codename Protein Powder)
heroku[web.1]: State changed from up to starting
heroku[web.1]: Process exited with status 137
heroku[web.1]: Process exited with status 0
heroku[web.1]: Starting process with command 'rackup sync.ru -E production'
heroku[web.1]: Stopping all processes with SIGTERM
heroku[web.1]: Process exited with status 137
heroku[web.1]: Stopping process with SIGKILL
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: State changed from crashed to start
heroku[web.1]: Error R10 (Boot timeout) Web process failed to bind to $PORT within 60 sec of launch

I deploy two heroku apps. 我部署了两个heroku应用程序。 One is thin server for Sync pub/sub system which is deployed with your Procfile: 一个是用于Sync pub / sub系统的瘦服务器,它与Procfile一起部署:

# this Procfile contains only the following line.
web:  bundle exec thin -p $PORT -e $RACK_ENV -R sync.ru start

And the other one is default web server deployed without Procfile. 另一个是没有Procfile部署的默认Web服务器。

Also, I set the server and adapter_javascript_url params to point to my thin server in sync.yml. 另外,我将serveradapter_javascript_url参数设置为指向sync.yml中的瘦服务器。

production:
  server: "http://xxx-sync.herokuapp.com/faye"
  adapter_javascript_url: "http://xxx-sync.herokuapp.com/faye/faye.js"
  adapter: "Faye"
  auth_token: <=% ENV["SYNC_AUTH_TOKEN"] %>
  async: true

This approach work with HTTP protocol for me. 这种方法适用于我的HTTP协议。

The message "Sure you're not looking for /faye ?" 消息“肯定你不是在寻找/ faye?” shows that thin server works fine. 表明瘦服务器工作正常。

Have struggled a bit to get it work on staging/production. 为了让它在分期/制作上有所作为而努力了。 Posting my answer in case if someone is not not on heroku but on private server like EC2/rackspace etc. 发布我的答案,以防万一有人不在heroku上,但在私人服务器上,如EC2 / rackspace等。

You need to start the server with below command 您需要使用以下命令启动服务器

RAILS_ENV=production bundle exec rackup sync.ru -E production

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

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