Skip to content

Commit

Permalink
Adding timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
peat committed Feb 12, 2012
1 parent f8e61c7 commit df44401
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
31 changes: 18 additions & 13 deletions server/lib/grind.rb
Expand Up @@ -10,23 +10,28 @@ class MHDApp
post '/grind' do
content_type :json

url = URI.parse( params['url'] )
person = params['person']
origin = params['origin']
out = { :error => "Timeout exceeded processing #{url}" }

# follow through all redirects!
url = follow_redirects( url )
# 5 second limit!
Timeout::timeout(5) {
url = URI.parse( params['url'] )
person = params['person']
origin = params['origin']

out = treasure_for( url )
# follow through all redirects!
url = follow_redirects( url )

out = out.collect do |t|
# add in person, origin, and save it
t[:person] = person
t[:origin] = origin
Treasure.create(t)
out = treasure_for( url )

t
end
out = out.collect do |t|
# add in person, origin, and save it
t[:person] = person
t[:origin] = origin
Treasure.create(t)

t
end
}

out.to_json
end
Expand Down
1 change: 1 addition & 0 deletions server/lib/mhd_app.rb
Expand Up @@ -4,6 +4,7 @@
require 'net/http'
require 'nokogiri'
require 'open-uri'
require 'timeout'

class MHDApp < Sinatra::Application

Expand Down

0 comments on commit df44401

Please sign in to comment.