Does Heroku support ActionController::Live? - ruby-on-rails

I have a Rails app hosted on Heroku and I want to add Server Sent Events functionalities, but I can't find any documentation or blog post specific for Heroku.
As not all servers (e.g. WEBrick) support ActionController::Live I was wondering what is the default server on Heroku and whether is possible to configure the environment (i.e. change server) to support SSEs.
Any further advice about the server to use and how to configure would be greatly appreciated.

I think my answer is not so widely helpfull, but you can try.
For the first thing:
create Procfile in rails root within the following content:
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
then add to Gemfile:
gem 'puma'
In above you can switch to thin, but consider link below (and many more details)
http://tenderlovemaking.com/2012/07/30/is-it-live.html

Heroku wouldn't necessarily be the issue here - it's an environment which allows your app to run (on Amazon EC2 I think)
Multi-Threaded Servers
The thing you've got to look for is the server software you use to run your app. Heroku basically takes your server gem & allows it to run with their processors, and other computing power; so it's really whether their platform can play ball with the right server
You're really looking for multi-threaded servers, which you can find here Is puma the ONLY multi-threaded rails 4 http server?
Puma
Rainbows! supports multiple concurrency models, including multithreading
Zbatery - Rack HTTP server without a fork stuck in it
Phusion Passenger 4 has supported multithreading since its beta stages
Thin does have a threaded mode which can be enabled by passing
--threaded or by setting threaded: true in the appropriate configuration file (e.g. bundle exec thin start --threaded)
Net::HTTP::Server, despite the lack of advertising, supports
multithreading; very minimalist

Related

Rails 5: Using Capybara with Phusion Passenger

I am trying to run specs on a Rails 5 app. However, I am seeing the following LoadError:
Failure/Error: raise LoadError, 'Capybara is unable to load puma for
its server, please add puma to your project or specify a different
server via something like Capybara.server = :webrick.'
I am using the passenger gem for the production server. Is there a way in which I can use passenger for the Capybara tests as well?
Thanks in advance
If you really want to use passenger to run your app while testing you will need to startup your app separately with passenger using the rails test environment (so it uses the test DB, etc) and then set
Capybara.run_server = false
Capybara.app_host = "http://<wherever the app is accessible>"
for your tests. This tells Capybara not to bother with running the app itself and to just connect to the app you're already running. You will also need to use something like database_cleaner to handle database resetting between tests, and be very careful to make sure you don't have any leftover requests running at the end of each test.
When running the tests with puma or webrick none of that is required (database_cleaner is generally required for rails < 5.1 but not 5.1+), because the web server is run in the same process (different threads) as the tests which allows Capybara to know when requests are still being processed and for Rails to share the DB connection with the tests. Overall you're just going to have a much smoother experience if you stick with puma or webrick for your tests.
I don't think you can do this:
The capybara documentation:
This block takes a rack app and a port and returns a
rack server listening on that port
From the passenger repo:
This is fundamentally incompatible with Phusion Passenger's model.
Such a Rack handler implies a single application and a single process.
Phusion Passenger runs multiple processes which can even serve multiple
applications.

rails: What happens when two web servers are specified in a Gemfile

If two web servers (say puma and unicorn) are specified
in the Gemfile, which one gets precedence?
I tried doing this myself but realized I was on windows with not much ruby support.
Long Answer with example:
you created app with rails 5.0.0, you get puma webserver by default.
you install unicorn gem. and you start the server by rails server still your server is puma. why ? because config/puma.rb file which generated with rails new application-name .
To start unicorn server you have to created one file for unicorn in config folder.
To start unicorn server you have to execute command like this unicorn -c config/unicorn.rb in your terminal.
I think this is the answer of your question.
Short answer:
You have tell rails explicitly which webserver you have to run. Rails will not decide which to run (in case of multiple web server).
I hope this clear your doubts.
Cheers

Capistrano 3.0.0

Has any one used Capistrano 3.0.0 ?
I'm new to rails and web development in general, and I've never used Capistrano before, and I need to deploy my app on Heroku with Capistrano in order to user sidekiq and redis-server.
Should I use an older version of Capistrano, where I could find more resource to help get started, or is this considered a bad thing ?
Any suggestions or tips would be very much appreciated.
Capistrano and Heroku are not compatible technology.
Heroku provides a git source control remote server. When you want to deploy code onto your Heroku app, you use git to push a copy of the code. This triggers a Heroku deployment through their process.
Capistrano is an SSH based system deployment framework. It allows you to connect via SSH to each server in your environment and issue commands with a large library of built-in functionality. Heroku does not allow SSH access to configure systems.
Do you have deploys/configuration working on Heroku at all? If not, you should start there with the basic Heroku Rails setup documents.
If you do have your web app running, but need Redis and Sidekiq, you will need to:
Provision a Redis database provider, like OpenRedis via a Heroku Addon: http://addons.heroku.com/
Setup Sidekiq in your Rails application (See Sidekiq docs: https://github.com/mperham/sidekiq)
Add a Sidekiq worker process in your Heroku Procfile within your app
Your app will then have a number of web processes from the Procfile running your Rails app front-end and a number of back-end asynchronous workers running Sidekiq.

Using JRuby and MRI for a common app

I need to use both JRuby and MRI for my rails app.
Here's the scenario -
My app uses a background server which handles a lot of threads. I'm having performance
issue with running it on MRI. The background server is started with a rake task and needs
to use the Rails environment.
I'm using Passenger for the Web Server. Since JRuby support for Passenger is quite recent,
I would like to go with using MRI.
Here's something I want -
This uses Ruby 1.9 to start the server :
sudo passenger start -p 80 -e production --user=deploy
and within the same app, this runs the background server -
jruby -S rake background_server:start_daemon RAILS_ENV=production
The problem is, the second command jruby -S rake asks for rebundling the app.
Is there any way I can get this in place?
Not in the same app. you'll need separate applications that run under different rubies if you want this to happen. in SOA architecture, you'd send a message to your background server for it to process a job.
So, in heroku you'd create one application for your web running in MRI; then you'd create an application in JRuby for your background processes. They'd communicate via a shared Redis or shared database.
I would recommend using Trinidad or Puma and keeping it all in JRuby though (as opposed to keep running passenger); it'll be a much simpler architecture.

How to set Thin as default in Rails 3

I've been starting Thin with thin -V start in development.
However, I would like Thin to be the default instead of WEBrick and to be able to start it with rails s.
Is there a way to set Thin as the default instead of WEBrick in Rails 3?
If that's not possible, is there at least a way to start it in the test environment automatically?
I sent a pull request on the Github repository of rack and it was accepted:
https://github.com/rack/rack/commit/b487f02b13f42c5933aa42193ed4e1c0b90382d7
In a near future, we will be able to use Thin just by adding gem 'thin' to our Gemfile and starting app with rails s.
Note that this may be a temporary measure, however.
I chose Thin because Mongrel was not maintained currently and no other server seemed to suit as an alternative to Mongrel.
Alternatively you could use foreman, especially if your web applications tend to get more complicated to run (background workers, clock processes to handle scheduling, etc.)
Taking thin as an example, you would need to create a Procfile in your Rails app with the following content:
web: bundle exec rails server thin -p $PORT
Then just:
foreman start
to start your server.
You can run rails3 with thin using rails server thin
See the output of rails server -h for more options.
In Gem file use: gem 'thin'
bundle install
then rails s it will take thin as default server for your project.

Resources