inquisitio 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjQ5Y2RhNzkxM2MwZmE5OTVmY2FkYjI0NGJmNDFlY2JkM2Q5ZmE5NQ==
5
- data.tar.gz: !binary |-
6
- NzE0OWNkZjkwZTk5M2VmZjQyOWIxOWYxNGUwMjBlZjhmNjlhZTc4MA==
2
+ SHA1:
3
+ metadata.gz: fea08d92d3503aaf286abbbfb90603071151987c
4
+ data.tar.gz: 89b2a9fa0fde1d9315aaa2b78e6f056b94fc865b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZTM0NWJmMjlmMTNmYjZlZDFkMTdhMzI2OTNmZmUzZDA4OWJkOTljYTk0OTYw
10
- Mjk3ODBiNWVjMjZjOTA5ZWZlOGI2MDcwZjE2NWI1M2I3N2ZhMmJlYjY0ZTY2
11
- NzZhNjA1MTZlY2Y1NzA2NzAyMDU1OTM0NWNkNGZmZTMxZTZiMGI=
12
- data.tar.gz: !binary |-
13
- ZWUwMzViZjJhMDQ3MjllY2NiOTc4MzY0MWNkZGI2MmYzN2M0NDNmMjg2MjRk
14
- YzMyOTMzYjM5ZTUzNGI2ZDBkYmNiNmQwOWM4ZWY0ZjMyZjJmNTYyZTAwOWMx
15
- Y2ZmMWEyNzZjOTZiOTlkNjZlOTk1MDJhZTYwZjdkNTE5MjMzOWU=
6
+ metadata.gz: acc88c23d6a6149742fd9b9b8d86aa6965bfd3271cab315d555670e04ddfb02d426bdf5515be1b6bf2b32541d032eba26890bb7c083799ba6ea59f73b1e50f38
7
+ data.tar.gz: 37b197462af739476a09d9058385054dc54f8b27e4cee3e27a9edb229c8ac758c8ae6157e44a15f7117943c3172df9e0f5d85b34ecbb052e394fa23c4d32d97c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.2.0 / 2014-01-14
2
+
3
+ [FEATURE] Add support for retrying query
4
+
1
5
  0.1.7 / 2013-12-13
2
6
 
3
7
  [FEATURE] Added dry-run configuration option to prevent data being sent to
@@ -10,14 +10,16 @@ module Inquisitio
10
10
  :document_endpoint,
11
11
  :default_search_size,
12
12
  :dry_run,
13
- :logger
13
+ :logger,
14
+ :max_attempts
14
15
  ]
15
-
16
+
16
17
  attr_writer *SETTINGS
17
18
 
18
19
  def initialize
19
20
  self.logger = Inquisitio::Logger.new
20
21
  self.dry_run = false
22
+ self.max_attempts = 3
21
23
  end
22
24
 
23
25
  SETTINGS.each do |setting|
@@ -18,6 +18,7 @@ module Inquisitio
18
18
  returns: [],
19
19
  with: {}
20
20
  }
21
+ @failed_attempts = 0
21
22
 
22
23
  yield(self) if block_given?
23
24
  end
@@ -33,7 +34,7 @@ module Inquisitio
33
34
  def records
34
35
  @records ||= begin
35
36
  klasses = {}
36
- map do |result|
37
+ results.map do |result|
37
38
  klass = result['data']['med_type'].first
38
39
  klasses[klass] ||= []
39
40
  klasses[klass] << result['data']['med_id'].first
@@ -102,20 +103,26 @@ module Inquisitio
102
103
  private
103
104
 
104
105
  def results
105
- if @results.nil?
106
- Inquisitio.config.logger.info("Performing search: #{search_url}")
107
- response = Excon.get(search_url)
108
- raise InquisitioError.new("Search failed with status code: #{response.status} Message #{response.body}") unless response.status == 200
109
- body = JSON.parse(response.body)
110
- @results = Results.new(body["hits"]["hit"],
111
- params[:page],
112
- params[:per],
113
- body["hits"]["found"])
114
- end
115
- @results
106
+ return @results unless @results.nil?
107
+
108
+ Inquisitio.config.logger.info("Performing search: #{search_url}")
109
+ response = Excon.get(search_url)
110
+ raise InquisitioError.new("Search failed with status code: #{response.status} Message #{response.body}") unless response.status == 200
111
+ body = JSON.parse(response.body)
112
+ @results = Results.new(body["hits"]["hit"],
113
+ params[:page],
114
+ params[:per],
115
+ body["hits"]["found"])
116
116
  rescue => e
117
- Inquisitio.config.logger.error("Exception Performing search: #{search_url} #{e}")
117
+ @failed_attempts += 1
118
+ Inquisitio.config.logger.error("Exception Performing search: #{search_url} #{e}")
119
+
120
+ if @failed_attempts < Inquisitio.config.max_attempts
121
+ Inquisitio.config.logger.error("Retrying search #{@failed_attempts}/#{Inquisitio.config.max_attempts}")
122
+ results
123
+ else
118
124
  raise InquisitioError.new("Exception performing search")
125
+ end
119
126
  end
120
127
 
121
128
  def search_url
@@ -1,3 +1,3 @@
1
1
  module Inquisitio
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,6 +19,10 @@ module Inquisitio
19
19
  assert_equal test_search_endpoint, Inquisitio.config.search_endpoint
20
20
  end
21
21
 
22
+ def test_search_endpoint
23
+ assert_equal 3, Inquisitio.config.max_attempts
24
+ end
25
+
22
26
  def test_search_endpoint
23
27
  search_endpoint = "test-search-endpoint"
24
28
  Inquisitio.config.search_endpoint = search_endpoint
@@ -211,6 +211,7 @@ module Inquisitio
211
211
  Excon.stub({}, {:body => 'Bad Happened', :status => 500})
212
212
 
213
213
  searcher = Searcher.where('Star Wars')
214
+ searcher.instance_variable_set(:@failed_attempts, 3)
214
215
 
215
216
  assert_raises(InquisitioError, "Search failed with status code 500") do
216
217
  searcher.search
@@ -221,12 +222,22 @@ module Inquisitio
221
222
  Excon.stub({}, lambda { |_| raise Excon::Errors::Timeout})
222
223
 
223
224
  searcher = Searcher.where('Star Wars')
225
+ searcher.instance_variable_set(:@failed_attempts, 3)
224
226
 
225
227
  assert_raises(InquisitioError) do
226
228
  searcher.search
227
229
  end
228
230
  end
229
231
 
232
+ def test_search_retries_when_failed_attempts_under_limit
233
+ Excon.expects(:get).raises(Excon::Errors::Timeout).times(3)
234
+
235
+ searcher = Searcher.where('Star Wars')
236
+ assert_raises(InquisitioError, "Search failed with status code 500") do
237
+ searcher.search
238
+ end
239
+ end
240
+
230
241
  def test_that_iterating_calls_results
231
242
  searcher = Searcher.where("star_wars")
232
243
  searcher.expects(results: [])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inquisitio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-12-13 00:00:00.000000000 Z
13
+ date: 2014-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: excon
@@ -30,14 +30,14 @@ dependencies:
30
30
  name: ruby_deep_clone
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ! '>='
33
+ - - '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ! '>='
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
@@ -58,42 +58,42 @@ dependencies:
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ! '>='
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ! '>='
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: mocha
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ! '>='
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ! '>='
82
+ - - '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: yard
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ! '>='
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ! '>='
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
@@ -165,12 +165,12 @@ require_paths:
165
165
  - lib
166
166
  required_ruby_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
- - - ! '>='
168
+ - - '>='
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ! '>='
173
+ - - '>='
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  requirements: []