Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Last active January 2, 2016 01:39
Show Gist options
  • Select an option

  • Save patmaddox/8231576 to your computer and use it in GitHub Desktop.

Select an option

Save patmaddox/8231576 to your computer and use it in GitHub Desktop.
require 'timeout'
class SearchesController
def post
search = Search.create! params[:search]
begin
timeout(3) do
while result.nil?
result = Cache.fetch(search.results_id)
end
end
render json: result
rescue TimeoutError
render status: WHATEVER_CODE, href: search_results_url(search)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment