kameleoon-client-ruby 3.20.0 → 3.21.0
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 +4 -4
- data/lib/kameleoon/client_readiness.rb +31 -21
- data/lib/kameleoon/kameleoon_client.rb +23 -4
- data/lib/kameleoon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea79d87e992d2f5bf9829c8082427c18251101be90f50c769b46242a1f4fc272
|
|
4
|
+
data.tar.gz: 305d07e5adee2b86cf58acc2b01f8a47f4161daeb06efbc8239e7a585ec355cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3319b271cf4053f01e9fab40b0133cd609a800f55fd3de84f19b76209d2fcbe5438672aa24a42dc39c1dd4dade97641956c2cff1f5c5c0cee8ece0d80636ca8
|
|
7
|
+
data.tar.gz: 10dfdd35cf97d0adb20ed4a866c4b6739be6ec11458c267a550bf02f6e5ae2542b282b2c30ac33ae94797e3e4a8ce8dd6187406ef1d85603c2d02d0b9f09d44f
|
|
@@ -3,37 +3,47 @@
|
|
|
3
3
|
require 'concurrent'
|
|
4
4
|
|
|
5
5
|
module Kameleoon
|
|
6
|
+
# ClientReadiness is a cross-thread latch signalling that the SDK has
|
|
7
|
+
# successfully loaded its configuration.
|
|
8
|
+
#
|
|
9
|
+
# It is created on the thread that builds the client but released (`set`) from
|
|
10
|
+
# the background thread(s) performing configuration fetches, so it relies on
|
|
11
|
+
# Concurrent::Event (which allows cross-thread release) rather than a
|
|
12
|
+
# read/write lock (whose write lock must be released by the acquiring thread).
|
|
13
|
+
#
|
|
14
|
+
# A failed fetch does NOT release the latch: the client keeps retrying in the
|
|
15
|
+
# background and the latch is released as soon as any fetch succeeds. Callers
|
|
16
|
+
# should bound their `wait` with a timeout so they are never blocked forever
|
|
17
|
+
# when the configuration can never be loaded.
|
|
6
18
|
class ClientReadiness
|
|
7
|
-
attr_reader :is_initializing, :success
|
|
8
|
-
|
|
9
19
|
def initialize
|
|
10
|
-
@is_initializing = false
|
|
11
20
|
@success = false
|
|
12
|
-
@
|
|
13
|
-
reset
|
|
21
|
+
@event = Concurrent::Event.new
|
|
14
22
|
end
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@is_initializing = true
|
|
20
|
-
@condition.acquire_write_lock
|
|
21
|
-
end
|
|
24
|
+
# @return [Boolean] whether the SDK has become ready (configuration loaded).
|
|
25
|
+
def success
|
|
26
|
+
@success
|
|
22
27
|
end
|
|
23
28
|
|
|
29
|
+
# Record a fetch outcome. A successful fetch marks the client ready and
|
|
30
|
+
# unblocks all waiting threads; a failed fetch is ignored so that a later
|
|
31
|
+
# successful retry can still release the latch. Idempotent and safe to call
|
|
32
|
+
# from any thread.
|
|
24
33
|
def set(success)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
34
|
+
return unless success
|
|
35
|
+
|
|
36
|
+
@success = true
|
|
37
|
+
@event.set
|
|
30
38
|
end
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
# Block until the SDK becomes ready or the timeout elapses.
|
|
41
|
+
#
|
|
42
|
+
# @param timeout [Numeric, nil] maximum number of seconds to wait;
|
|
43
|
+
# nil waits indefinitely.
|
|
44
|
+
# @return [Boolean] whether the SDK is ready.
|
|
45
|
+
def wait(timeout = nil)
|
|
46
|
+
@event.wait(timeout)
|
|
37
47
|
@success
|
|
38
48
|
end
|
|
39
49
|
end
|
|
@@ -92,9 +92,24 @@ module Kameleoon
|
|
|
92
92
|
site_code, config)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
##
|
|
96
|
+
# Block until the SDK has loaded its configuration and is ready to use.
|
|
97
|
+
#
|
|
98
|
+
# If the initial fetch fails the client keeps retrying in the background, so
|
|
99
|
+
# this method returns as soon as any fetch succeeds. The wait is always
|
|
100
|
+
# bounded by a timeout, so it never blocks indefinitely: when the timeout
|
|
101
|
+
# elapses before the configuration is loaded, the method returns false.
|
|
102
|
+
#
|
|
103
|
+
# @param [Integer, nil] timeout_millisecond Maximum time to wait, in
|
|
104
|
+
# milliseconds. When nil or negative, config.default_timeout_millisecond
|
|
105
|
+
# is applied.
|
|
106
|
+
# @return [Boolean] true if the SDK is ready, false if the timeout elapsed first.
|
|
107
|
+
def wait_init(timeout_millisecond = nil)
|
|
108
|
+
Logging::KameleoonLogger.info('CALL: KameleoonClient.wait_init(timeout_millisecond: %s)', timeout_millisecond)
|
|
109
|
+
if timeout_millisecond.nil? || timeout_millisecond.negative?
|
|
110
|
+
timeout_millisecond = @config.default_timeout_millisecond
|
|
111
|
+
end
|
|
112
|
+
result = @readiness.wait(timeout_millisecond / 1000.0)
|
|
98
113
|
Logging::KameleoonLogger.info('RETURN: KameleoonClient.wait_init -> (result: %s)', result)
|
|
99
114
|
result
|
|
100
115
|
end
|
|
@@ -822,7 +837,8 @@ module Kameleoon
|
|
|
822
837
|
Logging::KameleoonLogger.error('Initial configuration fetch failed: %s', e)
|
|
823
838
|
end
|
|
824
839
|
@readiness.set(ok)
|
|
825
|
-
|
|
840
|
+
real_time_update = ok && @data_manager.data_file.settings.real_time_update
|
|
841
|
+
manage_configuration_update(real_time_update)
|
|
826
842
|
end
|
|
827
843
|
end
|
|
828
844
|
|
|
@@ -834,6 +850,9 @@ module Kameleoon
|
|
|
834
850
|
rescue StandardError => e
|
|
835
851
|
Logging::KameleoonLogger.error('Error occurred during configuration fetching: %s', e)
|
|
836
852
|
end
|
|
853
|
+
# Release any threads still waiting in `wait_init` once a (re)fetch
|
|
854
|
+
# finally succeeds after an unsuccessful initial fetch.
|
|
855
|
+
@readiness.set(ok)
|
|
837
856
|
real_time_update = @data_manager.data_file.settings.real_time_update
|
|
838
857
|
if !ok && real_time_update
|
|
839
858
|
@data_manager.data_file.settings.real_time_update = false
|
data/lib/kameleoon/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kameleoon-client-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kameleoon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: em-http-request
|