ff-ruby-server-sdk 1.3.2 → 1.4.0

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: 2e06f7cec3eb38bff792b8406d0ff11fb487b8662c78ee9bdba3fdad46526e5f
4
- data.tar.gz: 7bd8b2c5d1cb6955bdcb9ca6363a6c8afa89cc8b8dbda7769dc0bf60eca62ba0
3
+ metadata.gz: 6411beee7ad512c4e70efc7d9fbd45c71835b18eff4bf41b8e056333074dc083
4
+ data.tar.gz: 1f13b504ffda1c95f4956813ec8dc887935340a26dcba09689864250dbf4589b
5
5
  SHA512:
6
- metadata.gz: 8eb61b5fa760cc59968d2ef51ddfe3263c3b75e9ec254304e9037a656a69318f4a2a7b6538c8ac5583394b5f0701af47c1ea2dbc1c94acb7dc830b4297c1d339
7
- data.tar.gz: 55af3f78ef20bc1cc0e667ef70fa60a5a7b41e79578db544038b0afc165470560cfd7566acf61f3902042b56d82f6264ef0d47ac121c149b6b77d31bfcf97b82
6
+ metadata.gz: f3cc5c07fe09718e260ca6ab19bb720d0db276a60f6ff9b9229a4374bdfeebce0b519e6edbbf82d202183382f55c447d3ed2293b614035ab4f8e2ff7880b4d56
7
+ data.tar.gz: 7771ae2a6823afffa73dbda7e49beceab7ad973e8ef4cb8dfdd1781ca0de7ee3a10822d19c58a749a90ffe492c72e5dbcaf0b8a05a04159c510e38d675ff25c9
@@ -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
- @config.logger.debug "Waiting for initialization to finish"
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
 
@@ -5,7 +5,7 @@ module Ff
5
5
  module Server
6
6
  module Sdk
7
7
 
8
- VERSION = "1.3.2"
8
+ VERSION = "1.4.0"
9
9
  end
10
10
  end
11
11
  end
data/scripts/sdk_specs.sh CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/bin/bash
2
2
 
3
3
  export ff_ruby_sdk="ff-ruby-server-sdk"
4
- export ff_ruby_sdk_version="1.3.2"
4
+ export ff_ruby_sdk_version="1.4.0"
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.3.2
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-09-09 00:00:00.000000000 Z
11
+ date: 2024-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake