ff-ruby-server-sdk 1.3.1 → 1.4.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/docs/further_reading.md +44 -0
- data/lib/ff/ruby/server/sdk/api/auth_service.rb +2 -1
- data/lib/ff/ruby/server/sdk/api/cf_client.rb +2 -4
- data/lib/ff/ruby/server/sdk/api/inner_client.rb +17 -4
- data/lib/ff/ruby/server/sdk/common/sdk_codes.rb +12 -0
- data/lib/ff/ruby/server/sdk/connector/harness_connector.rb +5 -0
- data/lib/ff/ruby/server/sdk/version.rb +1 -1
- data/scripts/sdk_specs.sh +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6411beee7ad512c4e70efc7d9fbd45c71835b18eff4bf41b8e056333074dc083
|
4
|
+
data.tar.gz: 1f13b504ffda1c95f4956813ec8dc887935340a26dcba09689864250dbf4589b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3cc5c07fe09718e260ca6ab19bb720d0db276a60f6ff9b9229a4374bdfeebce0b519e6edbbf82d202183382f55c447d3ed2293b614035ab4f8e2ff7880b4d56
|
7
|
+
data.tar.gz: 7771ae2a6823afffa73dbda7e49beceab7ad973e8ef4cb8dfdd1781ca0de7ee3a10822d19c58a749a90ffe492c72e5dbcaf0b8a05a04159c510e38d675ff25c9
|
data/docs/further_reading.md
CHANGED
@@ -24,6 +24,50 @@ client.init(apiKey, ConfigBuilder
|
|
24
24
|
| enableStream | analytics_enabled(false) | Enable streaming mode. | true |
|
25
25
|
| enableAnalytics | stream_enabled(true) | Enable analytics. Metrics data is posted every 60s | true |
|
26
26
|
|
27
|
+
## Client Initialization Options
|
28
|
+
The Harness Feature Flags SDK for Ruby provides flexible initialization strategies to accommodate various application requirements. You can choose between an asynchronous (non-blocking) or synchronous (blocking) approach to initialize the SDK.
|
29
|
+
|
30
|
+
### Asynchronous (Non-Blocking) Initialization
|
31
|
+
The SDK can be initialized asynchronously without blocking the main thread or requiring a callback. In this case, defaults will be served until the SDK completes the initialization process.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = CfClient.instance
|
35
|
+
client.init(api_key, config)
|
36
|
+
|
37
|
+
# Will serve default until the SDK completes initialization
|
38
|
+
result = client.bool_variation("bool_flag", target, false)
|
39
|
+
```
|
40
|
+
|
41
|
+
### Synchronous (Blocking) Initialization
|
42
|
+
|
43
|
+
In cases where it's critical to ensure the SDK is initialized before evaluating flags, the SDK offers a synchronous initialization method. This approach blocks the current thread until the SDK is fully initialized or the optional specified timeout (in milliseconds) period elapses.
|
44
|
+
|
45
|
+
The synchronous method is useful for environments where feature flag decisions are needed before continuing, such as during application startup.
|
46
|
+
|
47
|
+
You can use the `wait_for_initialization` method, optionally providing a timeout in milliseconds to prevent waiting indefinitely in case of unrecoverable isues, e.g. incorrect API key used.
|
48
|
+
|
49
|
+
**Usage with a timeout**
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
client = CfClient.instance
|
53
|
+
client.init(api_key, config)
|
54
|
+
|
55
|
+
client.wait_for_initialization
|
56
|
+
|
57
|
+
result = client.bool_variation("bool_flag", target, false)
|
58
|
+
```
|
59
|
+
|
60
|
+
**Usage without a timeout**
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
client = CfClient.instance
|
64
|
+
client.init(api_key, config)
|
65
|
+
|
66
|
+
client.wait_for_initialization(timeout_ms: 3000)
|
67
|
+
|
68
|
+
result = client.bool_variation("bool_flag", target, false)
|
69
|
+
```
|
70
|
+
|
27
71
|
## Logging Configuration
|
28
72
|
You can provide your own logger to the SDK i.e. using the moneta logger we can do this
|
29
73
|
|
@@ -89,8 +89,9 @@ class AuthService < Closeable
|
|
89
89
|
# 503 service unavailable
|
90
90
|
# 504 gateway timeout
|
91
91
|
# -1 OpenAPI error (timeout etc)
|
92
|
+
# 0 Un-categorised typhoeus error
|
92
93
|
case code
|
93
|
-
when 408,425,429,500,502,503,504,-1
|
94
|
+
when 408,425,429,500,502,503,504,-1, 0
|
94
95
|
return true
|
95
96
|
else
|
96
97
|
return false
|
@@ -50,11 +50,9 @@ class CfClient < Closeable
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def wait_for_initialization
|
54
|
-
|
53
|
+
def wait_for_initialization(timeout_ms: nil)
|
55
54
|
if @client != nil
|
56
|
-
|
57
|
-
@client.wait_for_initialization
|
55
|
+
@client.wait_for_initialization(timeout: timeout_ms)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -231,19 +231,23 @@ class InnerClient < ClientCallback
|
|
231
231
|
@initialized = true
|
232
232
|
end
|
233
233
|
|
234
|
-
def wait_for_initialization
|
235
|
-
|
234
|
+
def wait_for_initialization(timeout: nil)
|
236
235
|
synchronize do
|
236
|
+
SdkCodes::info_sdk_waiting_to_initialize(@config.logger, timeout)
|
237
237
|
|
238
|
-
|
238
|
+
start_time = Time.now
|
239
239
|
|
240
240
|
until @initialized
|
241
|
+
# Check if a timeout is specified and has been exceeded
|
242
|
+
if timeout && (Time.now - start_time) > (timeout / 1000.0)
|
243
|
+
@config.logger.warn "The SDK has timed out waiting to initialize with supplied timeout #{timeout} ms"
|
244
|
+
handle_initialization_failure
|
245
|
+
end
|
241
246
|
|
242
247
|
sleep(1)
|
243
248
|
end
|
244
249
|
|
245
250
|
if @failure
|
246
|
-
|
247
251
|
raise "Initialization failed"
|
248
252
|
end
|
249
253
|
|
@@ -251,8 +255,17 @@ class InnerClient < ClientCallback
|
|
251
255
|
end
|
252
256
|
end
|
253
257
|
|
258
|
+
|
254
259
|
protected
|
255
260
|
|
261
|
+
def handle_initialization_failure
|
262
|
+
@auth_service.close
|
263
|
+
@poll_processor.stop
|
264
|
+
@update_processor.stop
|
265
|
+
@metrics_processor.stop
|
266
|
+
on_auth_failed
|
267
|
+
end
|
268
|
+
|
256
269
|
def setup
|
257
270
|
|
258
271
|
@repository = StorageRepository.new(@config.cache, @repository_callback, @config.store, @config.logger)
|
@@ -14,6 +14,17 @@ class SdkCodes
|
|
14
14
|
logger.info SdkCodes.sdk_err_msg(1000)
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.info_sdk_waiting_to_initialize(logger, timeout)
|
18
|
+
if timeout
|
19
|
+
message = "with timeout: #{timeout} ms"
|
20
|
+
else
|
21
|
+
|
22
|
+
message = "with no timeout"
|
23
|
+
|
24
|
+
end
|
25
|
+
logger.info SdkCodes.sdk_err_msg(1003, message)
|
26
|
+
end
|
27
|
+
|
17
28
|
def self.info_sdk_auth_ok(logger)
|
18
29
|
logger.info SdkCodes.sdk_err_msg(2000)
|
19
30
|
end
|
@@ -76,6 +87,7 @@ class SdkCodes
|
|
76
87
|
1000 => "The SDK has successfully initialized",
|
77
88
|
1001 => "The SDK has failed to initialize due to the following authentication error:",
|
78
89
|
1002 => "The SDK has failed to initialize due to a missing or empty API key",
|
90
|
+
1003 => "The SDK is waiting for initialzation to complete",
|
79
91
|
# SDK_AUTH_2xxx
|
80
92
|
2000 => "Authenticated ok",
|
81
93
|
2001 => "Authentication failed with a non-recoverable error - defaults will be served",
|
@@ -46,6 +46,11 @@ class HarnessConnector < Connector
|
|
46
46
|
# determine if a timeout has occurred. This is fixed in 6.3.0 but requires Ruby version to be increased to 2.7
|
47
47
|
# https://github.com/OpenAPITools/openapi-generator/releases/tag/v6.3.0
|
48
48
|
@config.logger.warn "OpenapiClient::ApiError [\n\n#{e}\n]"
|
49
|
+
|
50
|
+
if e.code
|
51
|
+
return e.code
|
52
|
+
end
|
53
|
+
|
49
54
|
return -1
|
50
55
|
end
|
51
56
|
|
data/scripts/sdk_specs.sh
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ff-ruby-server-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 'Miloš Vasić, cyr.: Милош Васић'
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '13.
|
20
|
-
type: :
|
19
|
+
version: '13.2'
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '13.
|
26
|
+
version: '13.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '5.
|
34
|
-
type: :
|
33
|
+
version: '5.25'
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '5.
|
40
|
+
version: '5.25'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: standard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
48
|
-
type: :
|
47
|
+
version: '1.4'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rufus-scheduler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -305,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
305
305
|
- !ruby/object:Gem::Version
|
306
306
|
version: '0'
|
307
307
|
requirements: []
|
308
|
-
rubygems_version: 3.5.
|
308
|
+
rubygems_version: 3.5.16
|
309
309
|
signing_key:
|
310
310
|
specification_version: 4
|
311
311
|
summary: Harness is a feature management platform that helps teams to build better
|