Stephen Celis

Time-sensitive asset serving 12 Apr

You have a cron job regularly sending new files to an asset host with rsync. You’ve reduced the load on your application server, but how do you ensure that new files are served properly before your asset server synchronizes?

config/environments/production.rb

config.action_controller.asset_host = Proc.new { |path|
  case Time.at(path.split('?').last.to_i)
  when 1.hour.ago..Time.now
    nil
  else
    'assets.example.com'
  end
end