amplitude-experiment 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39fff5d1285490313a587d9df46b1cf68bb84c5672d9927871ba83b195bbf613
4
- data.tar.gz: 8f26de2e9de3585d5696646cd384841a732e9c0944520b479dc42ab423f5f168
3
+ metadata.gz: 2c2b4d645d6bc1a63154135eca42b2123dbaef5fb6597e77ea3c4d602235bbe7
4
+ data.tar.gz: b521d6b1f7af00b62fc9ec14e8c8e1db63a63b9330e8e73139fcf09ffb5f5dca
5
5
  SHA512:
6
- metadata.gz: 96bb141478ceb429381894466cd63fd937ddd8e27d4d5ac4ee4b02ed6bacfef34750f151fbfffbc088fb5562e3ee2aef23e4da9ed8907f591a37a9195fc5e8b9
7
- data.tar.gz: 631d94a409a81132540504f135b56b2b6ccdfb407e9e11f250486ee9cf6d74e481e5a2dc3e23e652ed07b42abde9ffb9d2cbd9f17e1128c4248b1e55e53e2d61
6
+ metadata.gz: 68d5921c26baf78c5f1dcff97e4b58124e35f5be6de93b02be240e593c12f67d32ecba973ea95cb8df66908132c280a55e94d9be2025f351c536129663359570
7
+ data.tar.gz: 5a66ce54c1ed89ae0bef261578ad006151c34292805aa6cf68725b7a61085089de4a96769401a52631fb2a57a759d89b0b7fe6a2e570ca25af49415badd5a1c2
@@ -15,6 +15,7 @@ require 'experiment/local/assignment/assignment_service'
15
15
  require 'experiment/local/assignment/assignment_config'
16
16
  require 'experiment/util/lru_cache'
17
17
  require 'experiment/util/hash'
18
+ require 'experiment/error'
18
19
 
19
20
  # Amplitude Experiment Module
20
21
  module AmplitudeExperiment
@@ -0,0 +1,11 @@
1
+ module AmplitudeExperiment
2
+ # FetchError
3
+ class FetchError < StandardError
4
+ attr_reader :status_code
5
+
6
+ def initialize(status_code, message)
7
+ super(message)
8
+ @status_code = status_code
9
+ end
10
+ end
11
+ end
@@ -61,12 +61,14 @@ module AmplitudeExperiment
61
61
  do_fetch(user, @config.fetch_timeout_millis)
62
62
  rescue StandardError => e
63
63
  @logger.error("[Experiment] Fetch failed: #{e.message}")
64
- begin
65
- return retry_fetch(user)
66
- rescue StandardError => err
67
- @logger.error("[Experiment] Retry Fetch failed: #{err.message}")
64
+ if should_retry_fetch?(e)
65
+ begin
66
+ retry_fetch(user)
67
+ rescue StandardError => err
68
+ @logger.error("[Experiment] Retry Fetch failed: #{err.message}")
69
+ end
68
70
  end
69
- throw e
71
+ raise e
70
72
  end
71
73
 
72
74
  # @param [User] user
@@ -108,6 +110,8 @@ module AmplitudeExperiment
108
110
  end_time = Time.now
109
111
  elapsed = (end_time - start_time) * 1000.0
110
112
  @logger.debug("[Experiment] Fetch complete in #{elapsed.round(3)} ms")
113
+ raise FetchError.new(response.code.to_i, "Fetch error response: status=#{response.code} #{response.message}") if response.code != '200'
114
+
111
115
  json = JSON.parse(response.body)
112
116
  variants = parse_json_variants(json)
113
117
  @logger.debug("[Experiment] Fetched variants: #{variants}")
@@ -140,5 +144,11 @@ module AmplitudeExperiment
140
144
  user.library = "experiment-ruby-server/#{VERSION}"
141
145
  user
142
146
  end
147
+
148
+ def should_retry_fetch?(err)
149
+ return err.status_code < 400 || err.status_code >= 500 || err.status_code == 429 if err.is_a?(FetchError)
150
+
151
+ true
152
+ end
143
153
  end
144
154
  end
@@ -1,3 +1,3 @@
1
1
  module AmplitudeExperiment
2
- VERSION = '1.2.5'.freeze
2
+ VERSION = '1.2.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amplitude-experiment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amplitude
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-30 00:00:00.000000000 Z
11
+ date: 2024-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -176,6 +176,7 @@ files:
176
176
  - lib/amplitude/utils.rb
177
177
  - lib/amplitude/workers.rb
178
178
  - lib/experiment/cookie.rb
179
+ - lib/experiment/error.rb
179
180
  - lib/experiment/factory.rb
180
181
  - lib/experiment/local/assignment/assignment.rb
181
182
  - lib/experiment/local/assignment/assignment_config.rb