Class: Apollo::Fetcher::SmartFetcher
Constant Summary
collapse
- @@DEFAULT_SLEEP =
0.1
- @@LAST_FETCH =
nil
Class Method Summary
collapse
Methods inherited from BaseFetcher
fetch_old, get_fake_headers
Class Method Details
.fetch(url, options = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/apollo_crawler/fetcher/smart_fetcher.rb', line 32
def self.fetch(url, options = {})
if(@@LAST_FETCH != nil)
now = DateTime.now
last = @@LAST_FETCH
diff = @@DEFAULT_SLEEP - (last - now)
sleep(diff)
end
res = BaseFetcher::fetch(url)
@@LAST_FETCH = DateTime.now
return res
end
|