I'm trying to set up the 'sync' gem to enable real time updates in my rails app. This uses Faye as a real time push service and thin as the webserver.
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. This is my setup:
In my gemfile:
gem 'faye'
gem 'thin', require: false
gem 'sync'
In my root folder, I have a sync.ru file
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 simply run:
rackup sync.ru -E production
This starts the thin web server and real time updates work in my app.
How can I get this working on Heroku?
I've tried adding the following to my procfile (no idea if this is the right thing to do)
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:
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. One is thin server for Sync pub/sub system which is deployed with your Procfile:
And the other one is default web server deployed without Procfile.
Also, I set the
server
andadapter_javascript_url
params to point to my thin server in sync.yml.This approach work with HTTP protocol for me.
The message "Sure you're not looking for /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.
You need to start the server with below command