Created
May 29, 2012 22:51
-
-
Save robotmay/2831250 to your computer and use it in GitHub Desktop.
The strange and wonderful world of forgotten Rails features: HTTP Streaming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browser_monitoring: | |
auto_instrument: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectsController < ApplicationController | |
respond_to :html | |
def index | |
@projects = Project.scoped | |
respond_with @projects, stream: true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectsController < ApplicationController | |
stream | |
def index | |
# rest of controller code | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@projects = Project.all | |
render :stream => true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 3 | |
timeout 30 | |
preload_app true | |
port = ENV["PORT"].to_i | |
listen port, tcp_nopush: false | |
before_fork do |server, worker| | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.connection.disconnect! | |
Rails.logger.info('Disconnected from ActiveRecord') | |
end | |
sleep 1 | |
end | |
after_fork do |server, worker| | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
Rails.logger.info('Connected to ActiveRecord') | |
end | |
if defined?(ActiveSupport::Cache::DalliStore) && Rails.cache.is_a?(ActiveSupport::Cache::DalliStore) | |
# Reset Rails's object cache | |
# Only works with DalliStore | |
Rails.cache.reset | |
# Reset Rails's session store | |
# If you know a cleaner way to find the session store instance, please let me know | |
ObjectSpace.each_object(ActionDispatch::Session::DalliStore) { |obj| obj.reset } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment