簡體   English   中英

在Heroku上使用rails sync gem與Faye和Thin在生產模式下

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

我正在嘗試設置'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

我部署了兩個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?” 表明瘦服務器工作正常。

為了讓它在分期/制作上有所作為而努力了。 發布我的答案,以防萬一有人不在heroku上,但在私人服務器上,如EC2 / rackspace等。

您需要使用以下命令啟動服務器

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM