flagsmith 4.1.0 → 4.1.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: c1951f9f2c2eebff1765ad5b1bbdcdd2502f33c0c86262d4450e53b5921c4646
4
- data.tar.gz: 0d2fe63cdde7a4da85d71b8a982a38c07b65d141eae3f174200d4cb990db8a6f
3
+ metadata.gz: 8b908dee8f4935d4c754400d2e314e8a61e545dc242490ca396704f6b00ef1e1
4
+ data.tar.gz: 4c9203ad57f71fb3699b78ccb9a50aa7b4c89eaf1433803d0c16e3b7644a91c3
5
5
  SHA512:
6
- metadata.gz: 6617e71586183e9dc163e21b857a8d26fd0698390b51066b4aa2a812831e1b44a4c076eb728e1586fc8ab604c359bc0652cb2f79e4426e6c1a8a5c5637106625
7
- data.tar.gz: c720ab5adbd784ca3447970d7eceb97f93c656779cddc75c5149c5437a62a8838107b692cc6e58c74e52f06a434e2e56032bc67597e844881a673bb1a08f6f14
6
+ metadata.gz: a41d33186ccd7bf6b7405a123186888ea9aef9e0890762b2384d1681b897ceed602e471eb4903190bf09b0c1c48a6b99a831053f10dde55cbcd6e9875851dfde
7
+ data.tar.gz: e654da93bb040ce2a08fa0cb6b15d167a2b557853fec1e8deb3cd45df124177998d7fb40e6ccae777cf8e62b0cdc72efd0cbd3a8e6fd4fcd894ed2b23d228c90
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flagsmith (4.1.0)
4
+ flagsmith (4.1.1)
5
5
  faraday (>= 2.0.1)
6
6
  faraday-retry
7
7
  semantic
@@ -39,7 +39,8 @@ GEM
39
39
  rainbow (3.1.1)
40
40
  rake (13.1.0)
41
41
  regexp_parser (2.9.0)
42
- rexml (3.2.6)
42
+ rexml (3.2.8)
43
+ strscan (>= 3.0.9)
43
44
  rspec (3.12.0)
44
45
  rspec-core (~> 3.12.0)
45
46
  rspec-expectations (~> 3.12.0)
@@ -68,6 +69,7 @@ GEM
68
69
  parser (>= 3.2.1.0)
69
70
  ruby-progressbar (1.13.0)
70
71
  semantic (1.6.1)
72
+ strscan (3.1.0)
71
73
  unicode-display_width (2.5.0)
72
74
  uri (0.13.0)
73
75
 
@@ -7,7 +7,7 @@ module Flagsmith
7
7
  OPTIONS = %i[
8
8
  environment_key api_url custom_headers request_timeout_seconds enable_local_evaluation
9
9
  environment_refresh_interval_seconds retries enable_analytics default_flag_handler
10
- offline_mode offline_handler logger
10
+ offline_mode offline_handler polling_manager_failure_limit logger
11
11
  ].freeze
12
12
 
13
13
  # Available Configs
@@ -38,6 +38,8 @@ module Flagsmith
38
38
  # bypasses requests to the api.
39
39
  # +offline_handler+ - A file object that contains a JSON serialization of
40
40
  # the entire environment, project, flags, etc.
41
+ # +polling_manager_failure_limit+ - An integer to control how long to suppress errors in
42
+ # the polling manager for local evaluation mode.
41
43
  # +logger+ - Pass your logger, default is Logger.new($stdout)
42
44
  #
43
45
  attr_reader(*OPTIONS)
@@ -89,6 +91,7 @@ module Flagsmith
89
91
  @default_flag_handler = opts[:default_flag_handler]
90
92
  @offline_mode = opts.fetch(:offline_mode, false)
91
93
  @offline_handler = opts[:offline_handler]
94
+ @polling_manager_failure_limit = opts.fetch(:polling_manager_failure_limit, 10)
92
95
  @logger = options.fetch(:logger, Logger.new($stdout).tap { |l| l.level = :debug })
93
96
  end
94
97
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -7,20 +7,33 @@ module Flagsmith
7
7
  class EnvironmentDataPollingManager
8
8
  include Flagsmith::SDK::Intervals
9
9
 
10
- def initialize(main, refresh_interval_seconds)
10
+ attr_reader :failures_since_last_update
11
+
12
+ def initialize(main, refresh_interval_seconds, polling_manager_failure_limit)
11
13
  @main = main
12
14
  @refresh_interval_seconds = refresh_interval_seconds
15
+ @polling_manager_failure_limit = polling_manager_failure_limit
16
+ @failures_since_last_update = 0
13
17
  end
14
18
 
19
+ # rubocop:disable Metrics/MethodLength
15
20
  def start
16
21
  update_environment = lambda {
17
22
  stop
18
- @interval = set_interval(@refresh_interval_seconds) { @main.update_environment }
23
+ @interval = set_interval(@refresh_interval_seconds) do
24
+ @main.update_environment
25
+ @failures_since_last_update = 0
26
+ rescue StandardError => e
27
+ @failures_since_last_update += 1
28
+ @main.config.logger.warn "Failure to update the environment due to an error: #{e}"
29
+ raise e if @failures_since_last_update > @polling_manager_failure_limit
30
+ end
19
31
  }
20
32
 
21
33
  # TODO: this call should be awaited for getIdentityFlags/getEnvironmentFlags when enableLocalEvaluation is true
22
34
  update_environment.call
23
35
  end
36
+ # rubocop:enable Metrics/MethodLength
24
37
 
25
38
  def stop
26
39
  return unless @interval
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flagsmith
4
- VERSION = '4.1.0'
4
+ VERSION = '4.1.1'
5
5
  end
data/lib/flagsmith.rb CHANGED
@@ -45,7 +45,7 @@ module Flagsmith
45
45
  #
46
46
  # :environment_key, :api_url, :custom_headers, :request_timeout_seconds, :enable_local_evaluation,
47
47
  # :environment_refresh_interval_seconds, :retries, :enable_analytics, :default_flag_handler,
48
- # :offline_mode, :offline_handler
48
+ # :offline_mode, :offline_handler, :polling_manager_failure_limit
49
49
  #
50
50
  # You can see full description in the Flagsmith::Config
51
51
 
@@ -107,7 +107,7 @@ module Flagsmith
107
107
  update_environment if @environment_data_polling_manager.nil?
108
108
 
109
109
  @environment_data_polling_manager ||= Flagsmith::EnvironmentDataPollingManager.new(
110
- self, environment_refresh_interval_seconds
110
+ self, environment_refresh_interval_seconds, @config.polling_manager_failure_limit
111
111
  ).tap(&:start)
112
112
  end
113
113
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flagsmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Stuart
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-04-19 00:00:00.000000000 Z
13
+ date: 2024-05-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler