crusher 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,24 @@ module Crusher
35
35
  }
36
36
 
37
37
  start_time = Time.now
38
- EM::Protocols::HttpClient.request(options).callback do |response|
38
+ em_request(start_time, uri, block, options)
39
+
40
+ end
41
+
42
+ private
43
+
44
+ def em_request(start_time, uri, block, options, times_to_retry=1)
45
+ begin
46
+ http = EM::Protocols::HttpClient.request(options)
47
+ rescue EventMachine::ConnectionError => error
48
+ unless times_to_retry > 3
49
+ @crush_session.logger.warn "retrying for #{times_to_retry} time with error \"#{error}\" failed request #{options.inspect}"
50
+ em_request(start_time, uri, block, options, (times_to_retry + 1))
51
+ end
52
+ @crush_session.logger.error "Failed after 3 tries with error \"#{error}\": #{options.inspect}"
53
+ raise error
54
+ end
55
+ http.callback do |response|
39
56
  duration = ((Time.now - start_time) * 1000).to_i
40
57
 
41
58
  response[:headers].each do |header|
@@ -45,10 +62,7 @@ module Crusher
45
62
 
46
63
  block.call(response, duration) if block
47
64
  end
48
-
49
65
  end
50
-
51
-
52
66
  end
53
67
 
54
68
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crusher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - phene