i18n-backend-http 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37d177679baecfda6a22c088c1266c42e088d8ef
4
- data.tar.gz: 44e1ab757b356505eae4d352f809f68a70a0adea
3
+ metadata.gz: 8560707e20d17044c7ab9dd52186e50660962e2e
4
+ data.tar.gz: 262db68db3e531ff89c696c1c16a7f274256a8bb
5
5
  SHA512:
6
- metadata.gz: 1b189828919827be728fa4ffc4d6b899627ea88ab95f370ec66cca81af78e44c026b8d7fc89e5d1288e6c96470c4ef37f1e8bec441872b3d118cb4e3c7549d6f
7
- data.tar.gz: e0a5cf51511a331b2146ca600fa4182b5afef6e0c886ee750f22cac2eab331aeb612f1b7b1181181298bc10793578418fe63a0b58919f2a289f10937580b7c2e
6
+ metadata.gz: 6e97e8e5040e1c158c3f22c4215d9869a4400a85f087c124563a9dfcb2adbfbad1fc944e7bb8f0482d053d78699fd5d96dc71dd4a8bb0d35b4cbbc98e5385543
7
+ data.tar.gz: 4369413f30ad285cd37f42f0068ce9ace672f7efa912c01067a41d17283b56379c2d79896f5ca3a3f8af964ce551dd9fc45643eca63115e090e3a61767b90b7e
@@ -11,11 +11,15 @@ module I18n
11
11
  class Http
12
12
  include ::I18n::Backend::Base
13
13
  FAILED_GET = {}.freeze
14
+ STATS_NAMESPACE = 'i18n-backend-http'.freeze
15
+ ALLOWED_STATS = Set[:download_fail, :open_retry, :read_retry].freeze
14
16
 
15
17
  def initialize(options)
16
18
  @options = {
17
19
  http_open_timeout: 1,
18
20
  http_read_timeout: 1,
21
+ http_open_retries: 0,
22
+ http_read_retries: 0,
19
23
  polling_interval: 10*60,
20
24
  cache: nil,
21
25
  poll: true,
@@ -104,9 +108,14 @@ module I18n
104
108
  end
105
109
 
106
110
  def download_translations(locale, etag:)
107
- result, etag = @http_client.download(path(locale), etag: etag)
108
- [parse_response(result), etag] if result
111
+ download_path = path(locale)
112
+
113
+ with_retry do
114
+ result, new_etag = @http_client.download(download_path, etag: etag)
115
+ [parse_response(result), new_etag] if result
116
+ end
109
117
  rescue => e
118
+ record(:download_fail, tags: ["exception:#{e.class}", "path:#{download_path}"])
110
119
  @options.fetch(:exception_handler).call(e)
111
120
  [self.class::FAILED_GET, nil]
112
121
  end
@@ -123,6 +132,28 @@ module I18n
123
132
  def lookup_key(translations, key)
124
133
  translations[key]
125
134
  end
135
+
136
+ def with_retry
137
+ open_tries ||= 0
138
+ read_tries ||= 0
139
+ yield
140
+ rescue Faraday::ConnectionFailed => e
141
+ raise unless e.instance_variable_get(:@wrapped_exception).is_a?(Net::OpenTimeout)
142
+ raise if (open_tries += 1) > @options[:http_open_retries]
143
+ record :open_retry
144
+ retry
145
+ rescue Faraday::TimeoutError => e
146
+ raise unless e.instance_variable_get(:@wrapped_exception).is_a?(Net::ReadTimeout)
147
+ raise if (read_tries += 1) > @options[:http_read_retries]
148
+ record :read_retry
149
+ retry
150
+ end
151
+
152
+ def record(event, options = {})
153
+ return unless statsd = @options[:statsd_client]
154
+ raise "Unknown statsd event type to record" unless ALLOWED_STATS.include?(event)
155
+ statsd.increment("#{STATS_NAMESPACE}.#{event}", tags: options[:tags])
156
+ end
126
157
  end
127
158
  end
128
159
  end
@@ -3,7 +3,7 @@ require 'faraday'
3
3
  module I18n
4
4
  module Backend
5
5
  class Http
6
- class I18n::Backend::Http::EtagHttpClient
6
+ class EtagHttpClient
7
7
  STATS_NAMESPACE = 'i18n-backend-http.etag_client'.freeze
8
8
 
9
9
  def initialize(options)
@@ -1,7 +1,7 @@
1
1
  module I18n
2
2
  module Backend
3
3
  class Http
4
- VERSION = Version = "0.3.3"
4
+ VERSION = Version = "0.3.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-backend-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: byebug
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description:
168
182
  email: michael@grosser.it
169
183
  executables: []