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 +4 -4
- data/lib/amplitude-experiment.rb +1 -0
- data/lib/experiment/error.rb +11 -0
- data/lib/experiment/remote/client.rb +15 -5
- data/lib/experiment/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c2b4d645d6bc1a63154135eca42b2123dbaef5fb6597e77ea3c4d602235bbe7
|
4
|
+
data.tar.gz: b521d6b1f7af00b62fc9ec14e8c8e1db63a63b9330e8e73139fcf09ffb5f5dca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68d5921c26baf78c5f1dcff97e4b58124e35f5be6de93b02be240e593c12f67d32ecba973ea95cb8df66908132c280a55e94d9be2025f351c536129663359570
|
7
|
+
data.tar.gz: 5a66ce54c1ed89ae0bef261578ad006151c34292805aa6cf68725b7a61085089de4a96769401a52631fb2a57a759d89b0b7fe6a2e570ca25af49415badd5a1c2
|
data/lib/amplitude-experiment.rb
CHANGED
@@ -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
|
@@ -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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
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
|
data/lib/experiment/version.rb
CHANGED
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.
|
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:
|
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
|