Skip to content

Commit 7d1a5db

Browse files
committed
Squash exceptions until a threshold level has breached
1 parent 97b02a8 commit 7d1a5db

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/flagsmith/sdk/pooling_manager.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,31 @@ module Flagsmith
77
class EnvironmentDataPollingManager
88
include Flagsmith::SDK::Intervals
99

10-
def initialize(main, refresh_interval_seconds)
10+
def initialize(main, refresh_interval_seconds, polling_manager_failure_limit)
1111
@main = main
1212
@refresh_interval_seconds = refresh_interval_seconds
13+
@polling_manager_failure_limit = polling_manager_failure_limit
14+
@failures_since_last_update = 0
1315
end
1416

17+
# rubocop:disable Metrics/MethodLength
1518
def start
1619
update_environment = lambda {
1720
stop
18-
@interval = set_interval(@refresh_interval_seconds) { @main.update_environment }
21+
@interval = set_interval(@refresh_interval_seconds) do
22+
@main.update_environment
23+
@failures_since_last_update = 0
24+
rescue StandardError => e
25+
@failures_since_last_update += 1
26+
@main.config.logger.warn "Failure to update the environment due to an error: #{e}"
27+
raise e if @failures_since_last_update > @polling_manager_failure_limit
28+
end
1929
}
2030

2131
# TODO: this call should be awaited for getIdentityFlags/getEnvironmentFlags when enableLocalEvaluation is true
2232
update_environment.call
2333
end
34+
# rubocop:enable Metrics/MethodLength
2435

2536
def stop
2637
return unless @interval

0 commit comments

Comments
 (0)