Created
July 11, 2012 11:50
-
-
Save robotmay/3089873 to your computer and use it in GitHub Desktop.
Scaling down
This file contains hidden or 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 ddg_info | |
@ddg_info ||= Rails.cache.fetch("places/#{id}-#{updated_at}/ddg_info", expires_in: 3.days) do | |
data = DDG.zeroClickInfo(name) | |
end | |
end |
This file contains hidden or 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
javascript: | |
$(document).ready(function() { | |
$("#ddg_info").load("/places/#{@place.slug}/ddg_info"); | |
#ddg_info |
This file contains hidden or 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 ddg_info | |
@place = Place.visible.find(params[:id]) | |
respond_with @place do |f| | |
f.html { render partial: "ddg_info" } | |
end | |
end |
This file contains hidden or 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
resources :places do | |
member do | |
get 'ddg_info' | |
end | |
end |
This file contains hidden or 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 |
This file contains hidden or 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 work(interval = 5.0, &block) | |
interval = Float(interval) | |
$0 = "resque: Starting" | |
startup | |
loop do | |
break if shutdown? | |
pause if should_pause? | |
if job = reserve(interval) | |
log "got: #{job.inspect}" | |
job.worker = self | |
run_hook :before_fork, job | |
working_on job | |
if @child = fork | |
srand # Reseeding | |
procline "Forked #{@child} at #{Time.now.to_i}" | |
Process.wait(@child) | |
else | |
procline "Processing #{job.queue} since #{Time.now.to_i}" | |
perform(job, &block) | |
exit! unless @cant_fork | |
end | |
done_working | |
@child = nil | |
else | |
break if interval.zero? | |
log! "Timed out after #{interval} seconds" | |
procline paused? ? "Paused" : "Waiting for #{@queues.join(',')}" | |
end | |
end | |
ensure | |
unregister_worker | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment