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

问题描述 投票:3回答:2

我正在尝试设置'sync'gem以在我的rails应用程序中启用实时更新。 这使用Faye作为实时推送服务,并使用瘦身作为网络服务器。

我对此非常陌生。所以任何建议都表示赞赏。

我在我的本地服务器上工作,但不知道如何让它在heroku上的生产模式下工作。 这是我的设置:

在我的gemfile中:

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

在我的根文件夹中,我有一个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

在我的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

在我的本地服务器上,我只是运行:

rackup sync.ru -E production

这启动了瘦Web服务器,并在我的应用程序中实时更新。

我怎样才能在Heroku上运行?

我已经尝试将以下内容添加到我的proc文件中(不知道这是否正确)

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

当我尝试加载我的应用程序时,我的浏览器显示以下文本:

Sure you're not looking for /faye ?

我的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
ruby-on-rails heroku webserver thin faye
2个回答
3
投票

我部署了两个heroku应用程序。 一个是用于Sync pub / sub系统的瘦服务器,它与Procfile一起部署:

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

另一个是没有Procfile部署的默认Web服务器。

另外,我将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

这种方法适用于我的HTTP协议。

消息“肯定你不是在寻找/ faye?” 表明瘦服务器工作正常。


0
投票

为了让它在分期/制作上有所作为而努力了。 发布我的答案,以防万一有人不在heroku上,但在私人服务器上,如EC2 / rackspace等。

您需要使用以下命令启动服务器

RAILS_ENV=production bundle exec rackup sync.ru -E production
© www.soinside.com 2019 - 2024. All rights reserved.