Skip to content

Instantly share code, notes, and snippets.

@robotmay
Created May 29, 2012 22:51
Show Gist options
  • Save robotmay/2831250 to your computer and use it in GitHub Desktop.
Save robotmay/2831250 to your computer and use it in GitHub Desktop.
The strange and wonderful world of forgotten Rails features: HTTP Streaming
browser_monitoring:
auto_instrument: false
class ProjectsController < ApplicationController
respond_to :html
def index
@projects = Project.scoped
respond_with @projects, stream: true
end
end
class ProjectsController < ApplicationController
stream
def index
# rest of controller code
end
end
def index
@projects = Project.all
render :stream => true
end
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