unleash 6.4.0 → 6.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a76eb26bedcade3ed88389aa909f7ead99177e336509bc4fd99d85c4703f1405
4
- data.tar.gz: 43410bf468ac4fd3b56af79a354eb84794c40c67b6c2d96c27bdf26772b1c54d
3
+ metadata.gz: 6c28fb398c92bd470282a94e7fe07b910fa4afed65381da67231c60c2b2960c2
4
+ data.tar.gz: 3a5b78a63ccfcec23ed8eba1e2168a5be7f183ca0c3beac0eb6497d1d4d6678c
5
5
  SHA512:
6
- metadata.gz: 3e43cbef4ba85e84265f10b9414eba95c92aeb59792a40318e15df37313ee5a6b99ce3c3e3e89d465c56e40fff92e61ed4115766d59b6ee9147c2d2c5920ebf7
7
- data.tar.gz: 2401fa3bf2d0f824d7da3cf2e01cc4c20fe740f26d2019f89554adbbc67fdc5c0f4fa65003e143391b14ea2466314db36852edd0ccefca8178f6545e3186170d
6
+ metadata.gz: 3d66480a2211bc60a0ddb2899d189a7966be1659f8618873233c8e419f2261dc5cf13cf79f747d36039af5f9ce1ead45fb4e3bc4140d420d4d59369a9a995bc4
7
+ data.tar.gz: ba06afc53ff6d2806d6bbf18cc93e2287ae327f42cb6699f663a3f2f5bb9abc6e3f71ce02ba7fe18f48bdcb9fb1913c2d9cc4a6be2d05bae6f740def1a4281d5
data/CHANGELOG.md CHANGED
@@ -13,6 +13,11 @@ Note: These changes are not considered notable:
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [6.4.1] - 2025-12-04
17
+
18
+ ### Changed
19
+ - Bump yggdrasil-engine
20
+
16
21
  ## [6.4.0] - 2025-08-12
17
22
  ### Added
18
23
  - Experimental streaming support
data/README.md CHANGED
@@ -28,7 +28,7 @@ You can use this client with [Unleash Enterprise](https://www.getunleash.io/pric
28
28
  Add this line to your application's Gemfile:
29
29
 
30
30
  ```ruby
31
- gem 'unleash', '~> 6.3.0'
31
+ gem 'unleash', '~> 6.4.1'
32
32
  ```
33
33
 
34
34
  And then execute:
@@ -0,0 +1,24 @@
1
+ require 'unleash/configuration'
2
+
3
+ module Unleash
4
+ class BackupFileReader
5
+ def self.read!
6
+ Unleash.logger.debug "read!()"
7
+
8
+ backup_file = Unleash.configuration.backup_file
9
+ return nil unless File.exist?(backup_file)
10
+
11
+ File.read(backup_file)
12
+ rescue IOError => e
13
+ # :nocov:
14
+ Unleash.logger.error "Unable to read the backup_file: #{e}"
15
+ # :nocov:
16
+ nil
17
+ rescue StandardError => e
18
+ # :nocov:
19
+ Unleash.logger.error "Unable to extract valid data from backup_file. Exception thrown: #{e}"
20
+ # :nocov:
21
+ nil
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'unleash/configuration'
2
+
3
+ module Unleash
4
+ class BackupFileWriter
5
+ def self.save!(toggle_data)
6
+ Unleash.logger.debug "Will save toggles to disk now"
7
+
8
+ backup_file = Unleash.configuration.backup_file
9
+ backup_file_tmp = "#{backup_file}.tmp-#{Process.pid}"
10
+
11
+ File.open(backup_file_tmp, "w") do |file|
12
+ file.write(toggle_data)
13
+ end
14
+ File.rename(backup_file_tmp, backup_file)
15
+ rescue StandardError => e
16
+ # This is not really the end of the world. Swallowing the exception.
17
+ Unleash.logger.error "Unable to save backup file. Exception thrown #{e.class}:'#{e}'"
18
+ Unleash.logger.error "stacktrace: #{e.backtrace}"
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Unleash
2
- CLIENT_SPECIFICATION_VERSION = "5.2.0".freeze
2
+ CLIENT_SPECIFICATION_VERSION = "5.2.2".freeze
3
3
  end
@@ -1,4 +1,6 @@
1
1
  require 'unleash/streaming_event_processor'
2
+ require 'unleash/bootstrap/handler'
3
+ require 'unleash/backup_file_reader'
2
4
  require 'unleash/util/event_source_wrapper'
3
5
 
4
6
  module Unleash
@@ -10,6 +12,20 @@ module Unleash
10
12
  self.event_source = nil
11
13
  self.event_processor = Unleash::StreamingEventProcessor.new(engine)
12
14
  self.running = false
15
+
16
+ begin
17
+ # if bootstrap configuration is available, initialize. Otherwise read backup file
18
+ if Unleash.configuration.use_bootstrap?
19
+ bootstrap(engine)
20
+ else
21
+ read_backup_file!(engine)
22
+ end
23
+ rescue StandardError => e
24
+ # fall back to reading the backup file
25
+ Unleash.logger.warn "StreamingClientExecutor was unable to initialize, attempting to read from backup file."
26
+ Unleash.logger.debug "Exception Caught: #{e}"
27
+ read_backup_file!(engine)
28
+ end
13
29
  end
14
30
 
15
31
  def run(&_block)
@@ -81,5 +97,18 @@ module Unleash
81
97
  Unleash.logger.error "Streaming client #{self.name} threw exception #{e.class}: '#{e}'"
82
98
  Unleash.logger.debug "stacktrace: #{e.backtrace}"
83
99
  end
100
+
101
+ def read_backup_file!(engine)
102
+ backup_data = Unleash::BackupFileReader.read!
103
+ engine.take_state(backup_data) if backup_data
104
+ end
105
+
106
+ def bootstrap(engine)
107
+ bootstrap_payload = Unleash::Bootstrap::Handler.new(Unleash.configuration.bootstrap_config).retrieve_toggles
108
+ engine.take_state(bootstrap_payload)
109
+
110
+ # reset Unleash.configuration.bootstrap_data to free up memory, as we will never use it again
111
+ Unleash.configuration.bootstrap_config = nil
112
+ end
84
113
  end
85
114
  end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'unleash/backup_file_writer'
2
3
 
3
4
  module Unleash
4
5
  class StreamingEventProcessor
@@ -41,7 +42,8 @@ module Unleash
41
42
  def handle_updated_event(event)
42
43
  handle_delta_event(event.data)
43
44
 
44
- # TODO: update backup file
45
+ full_state = @toggle_engine.get_state
46
+ Unleash::BackupFileWriter.save!(full_state)
45
47
  rescue JSON::ParserError => e
46
48
  Unleash.logger.error "Unable to parse JSON from streaming event data. Exception thrown #{e.class}: '#{e}'"
47
49
  Unleash.logger.debug "stacktrace: #{e.backtrace}"
@@ -1,5 +1,7 @@
1
1
  require 'unleash/configuration'
2
2
  require 'unleash/bootstrap/handler'
3
+ require 'unleash/backup_file_writer'
4
+ require 'unleash/backup_file_reader'
3
5
  require 'net/http'
4
6
  require 'json'
5
7
  require 'yggdrasil_engine'
@@ -23,10 +25,10 @@ module Unleash
23
25
  fetch
24
26
  end
25
27
  rescue StandardError => e
26
- # fail back to reading the backup file
28
+ # fall back to reading the backup file
27
29
  Unleash.logger.warn "ToggleFetcher was unable to fetch from the network, attempting to read from backup file."
28
30
  Unleash.logger.debug "Exception Caught: #{e}"
29
- read!
31
+ read_backup_file!
30
32
  end
31
33
 
32
34
  # once initialized, somewhere else you will want to start a loop with fetch()
@@ -54,25 +56,7 @@ module Unleash
54
56
  # always synchronize with the local cache when fetching:
55
57
  update_engine_state!(response.body)
56
58
 
57
- save! response.body
58
- end
59
-
60
- def save!(toggle_data)
61
- Unleash.logger.debug "Will save toggles to disk now"
62
-
63
- backup_file = Unleash.configuration.backup_file
64
- backup_file_tmp = "#{backup_file}.tmp"
65
-
66
- self.toggle_lock.synchronize do
67
- File.open(backup_file_tmp, "w") do |file|
68
- file.write(toggle_data)
69
- end
70
- File.rename(backup_file_tmp, backup_file)
71
- end
72
- rescue StandardError => e
73
- # This is not really the end of the world. Swallowing the exception.
74
- Unleash.logger.error "Unable to save backup file. Exception thrown #{e.class}:'#{e}'"
75
- Unleash.logger.error "stacktrace: #{e.backtrace}"
59
+ Unleash::BackupFileWriter.save! response.body
76
60
  end
77
61
 
78
62
  private
@@ -88,25 +72,9 @@ module Unleash
88
72
  Unleash.logger.error "Failed to hydrate state: #{e.backtrace}"
89
73
  end
90
74
 
91
- def read!
92
- Unleash.logger.debug "read!()"
93
- backup_file = Unleash.configuration.backup_file
94
- return nil unless File.exist?(backup_file)
95
-
96
- backup_data = File.read(backup_file)
97
- update_engine_state!(backup_data)
98
- rescue IOError => e
99
- # :nocov:
100
- Unleash.logger.error "Unable to read the backup_file: #{e}"
101
- # :nocov:
102
- rescue JSON::ParserError => e
103
- # :nocov:
104
- Unleash.logger.error "Unable to parse JSON from existing backup_file: #{e}"
105
- # :nocov:
106
- rescue StandardError => e
107
- # :nocov:
108
- Unleash.logger.error "Unable to extract valid data from backup_file. Exception thrown: #{e}"
109
- # :nocov:
75
+ def read_backup_file!
76
+ backup_data = Unleash::BackupFileReader.read!
77
+ update_engine_state!(backup_data) if backup_data
110
78
  end
111
79
 
112
80
  def bootstrap
@@ -1,3 +1,3 @@
1
1
  module Unleash
2
- VERSION = "6.4.0".freeze
2
+ VERSION = "6.4.1".freeze
3
3
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.required_ruby_version = ">= 2.7"
25
25
 
26
26
  spec.add_dependency "ld-eventsource", "2.2.4" unless RUBY_ENGINE == 'jruby'
27
- spec.add_dependency "yggdrasil-engine", "~> 1.0.4"
27
+ spec.add_dependency "yggdrasil-engine", "~> 1.1.1"
28
28
 
29
29
  spec.add_dependency "base64", "~> 0.3.0"
30
30
  spec.add_dependency "logger", "~> 1.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unleash
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.0
4
+ version: 6.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renato Arruda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-12 00:00:00.000000000 Z
11
+ date: 2025-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ld-eventsource
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.4
33
+ version: 1.1.1
34
34
  type: :runtime
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: 1.0.4
40
+ version: 1.1.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: base64
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -209,6 +209,8 @@ files:
209
209
  - examples/simple.rb
210
210
  - examples/streaming.rb
211
211
  - lib/unleash.rb
212
+ - lib/unleash/backup_file_reader.rb
213
+ - lib/unleash/backup_file_writer.rb
212
214
  - lib/unleash/bootstrap/configuration.rb
213
215
  - lib/unleash/bootstrap/handler.rb
214
216
  - lib/unleash/bootstrap/provider/base.rb
@@ -249,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
251
  - !ruby/object:Gem::Version
250
252
  version: '0'
251
253
  requirements: []
252
- rubygems_version: 3.5.22
254
+ rubygems_version: 3.4.20
253
255
  signing_key:
254
256
  specification_version: 4
255
257
  summary: Unleash feature toggle client.