ruby on rails - Fast way to check if page is online -


i using nokogiri parsing xml.

problem in response time of external resource. works fine. respond time can on 30 seconds. returns different error codes. need find out fastest way know if xml ready requested open-uri. , make actual request.

what doing setting timeout 5 seconds prevent delays.

begin   timeout::timeout(5)      link = uri.escape("http://domain.org/timetable.xml")     @doc  = nokogiri::html(open(link))   end rescue timeout::error   @error = "data server offline" end 

for checks @ level code shows, you'll need cooperation remote service, e.g., conditional head requests and/or etag comparison (those own preference.) looks may have of returns error codes, though if error codes in xml payload they're not going , of course, if remote service's responsiveness variable fluctuate between check , subsequent main request.

fwiw: if you're looking improve app's responsiveness when using data, there cache approaches can use, e.g., use soft-ttl lower main ttl that, when expired, causes cache code return cached xml , kick off async job refetch data it's fresher next request. or use repeating worker keep cache fresh.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -