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

I am trying to set up a "sync" gem to enable live updates in my rails application. It uses Faye as a real-time push service and thin as a web server.

I really love this. Therefore, any advice is appreciated.

I have it working on my local server but dont know how to make it work in production mode on hero. This is my setup:

In my gemfile:

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

      

In my root folder I have a 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

# 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 just run:

rackup sync.ru -E production

      

This will launch a thin web server and live updates in my application.

How can I get this to work on Heroku?

I tried to add the following to my procfile (not sure if this is the right way to do this)

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

      

When I try to load the application, the following text is displayed in my browser:

Sure you're not looking for /faye ?

      

And my heroku log says:

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

      

+3


source to share


2 answers


I am deploying two heroku apps. One is a thin server for Sync pub / sub system that is deployed with your Procfile:

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

      

And the other is the default web server, deployed without Procfile.

Also, I set the parameters server

and adapter_javascript_url

to point to my thin server in 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 works with the HTTP protocol for me.

The message "Surely you're not looking for / faye?" shows that the thin server is working fine.

+3


source


Did a bit of work to get him to work on the staging / production. Sending my answer in case someone is not on heroic, but on a private server like EC2 / rackspace etc.

You need to start the server with the command



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

      

0


source







All Articles