prefab-cloud-ruby 0.23.2 → 0.23.3

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: 6e93ba84e2ea630c852605f1bf814b5388dcaa8fd83025402d2dbc9afa8340cc
4
- data.tar.gz: 8a751a537cbdf658015630b26e5cdc4d284bcc018c702712e60148e68890f0c0
3
+ metadata.gz: 45234586612606d2efe94b569039c7f7866b948b1cc9ef1d252c3af68b678ac0
4
+ data.tar.gz: c4ca19037512f306fe4fe62a6031d56153a68d549e58a64e3754050af6b91948
5
5
  SHA512:
6
- metadata.gz: f460a0d55982126a5fb1591d380936355ab175e93963dddf18aba9a5b6c2f599d36784afc6afe85aef01870d3069d3aab1cb52967a1a508f2d76aa6287b3599f
7
- data.tar.gz: 1ce748c099c1414b98ca4476ec392e46068984196f4d6b261b6ee3acf696b86ae237ff63121a9a5050b500bd53fc957aadea7cec9d586cde75a3b8c4e543967c
6
+ metadata.gz: 1562416434735eb380f3cc7e159120a43e4f18e22f486020cfe7a35dc0c66f2c10a04104e46120c6f455a70ff7078c35ce16978bb1a111669686971be3a9c432
7
+ data.tar.gz: 4671527a60e7166e3acbeca47bbe211d405ceda58600c621406cf865b0942864d7b2d7c5f71c8fbb7ccc0e020113cf8921f7dcf5a9fe5b7a81b887392ef35460
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.23.2
1
+ 0.23.3
@@ -0,0 +1,16 @@
1
+ module Prefab
2
+ class ExponentialBackoff
3
+ def initialize(max_delay:, initial_delay: 2, multiplier: 2)
4
+ @initial_delay = initial_delay
5
+ @max_delay = max_delay
6
+ @multiplier = multiplier
7
+ @delay = initial_delay
8
+ end
9
+
10
+ def call
11
+ delay = @delay
12
+ @delay = [@delay * @multiplier, @max_delay].min
13
+ delay
14
+ end
15
+ end
16
+ end
@@ -14,9 +14,13 @@ module Prefab
14
14
 
15
15
  def initialize(client:, max_paths:, sync_interval:)
16
16
  @max_paths = max_paths
17
- @sync_interval = sync_interval
18
17
  @client = client
19
18
  @start_at = now
19
+ @sync_interval = if sync_interval.is_a?(Numeric)
20
+ proc { sync_interval }
21
+ else
22
+ sync_interval || ExponentialBackoff.new(initial_delay: 8, max_delay: 60 * 10)
23
+ end
20
24
 
21
25
  @pool = Concurrent::ThreadPoolExecutor.new(
22
26
  fallback_policy: :discard,
@@ -78,10 +82,10 @@ module Prefab
78
82
 
79
83
  def start_periodic_sync
80
84
  Thread.new do
81
- log_internal "Initialized log path collector instance_hash=#{@client.instance_hash} max_paths=#{@max_paths} sync_interval=#{@sync_interval}"
85
+ log_internal "Initialized log path collector instance_hash=#{@client.instance_hash} max_paths=#{@max_paths}"
82
86
 
83
87
  loop do
84
- sleep @sync_interval
88
+ sleep @sync_interval.call
85
89
  sync
86
90
  end
87
91
  end
@@ -39,7 +39,6 @@ module Prefab
39
39
  end
40
40
 
41
41
  DEFAULT_MAX_PATHS = 1_000
42
- DEFAULT_SYNC_INTERVAL = 60
43
42
 
44
43
  private def init(
45
44
  api_key: ENV['PREFAB_API_KEY'],
@@ -62,7 +61,7 @@ module Prefab
62
61
  prefab_envs: ENV['PREFAB_ENVS'].nil? ? [] : ENV['PREFAB_ENVS'].split(','),
63
62
  collect_logs: true,
64
63
  collect_max_paths: DEFAULT_MAX_PATHS,
65
- collect_sync_interval: DEFAULT_SYNC_INTERVAL
64
+ collect_sync_interval: nil
66
65
  )
67
66
  @api_key = api_key
68
67
  @logdev = logdev
@@ -8,6 +8,7 @@ require 'openssl'
8
8
  require 'ld-eventsource'
9
9
  require 'prefab_pb'
10
10
  require 'prefab/error'
11
+ require 'prefab/exponential_backoff'
11
12
  require 'prefab/errors/initialization_timeout_error'
12
13
  require 'prefab/errors/invalid_api_key_error'
13
14
  require 'prefab/errors/missing_default_error'
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 0.23.2 ruby lib
5
+ # stub: prefab-cloud-ruby 0.23.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.23.2"
9
+ s.version = "0.23.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2023-04-04"
14
+ s.date = "2023-04-07"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "lib/prefab/errors/initialization_timeout_error.rb",
46
46
  "lib/prefab/errors/invalid_api_key_error.rb",
47
47
  "lib/prefab/errors/missing_default_error.rb",
48
+ "lib/prefab/exponential_backoff.rb",
48
49
  "lib/prefab/feature_flag_client.rb",
49
50
  "lib/prefab/internal_logger.rb",
50
51
  "lib/prefab/local_config_parser.rb",
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
71
72
  "test/test_config_resolver.rb",
72
73
  "test/test_config_value_unwrapper.rb",
73
74
  "test/test_criteria_evaluator.rb",
75
+ "test/test_exponential_backoff.rb",
74
76
  "test/test_feature_flag_client.rb",
75
77
  "test/test_helper.rb",
76
78
  "test/test_integration.rb",
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class TestExponentialBackoff < Minitest::Test
6
+ def test_backoff
7
+ backoff = Prefab::ExponentialBackoff.new(max_delay: 120)
8
+
9
+ assert_equal 2, backoff.call
10
+ assert_equal 4, backoff.call
11
+ assert_equal 8, backoff.call
12
+ assert_equal 16, backoff.call
13
+ assert_equal 32, backoff.call
14
+ assert_equal 64, backoff.call
15
+ assert_equal 120, backoff.call
16
+ assert_equal 120, backoff.call
17
+ end
18
+ end
@@ -47,8 +47,7 @@ class TestLogPathCollector < Minitest::Test
47
47
  prefab_config_override_dir: 'none',
48
48
  prefab_config_classpath_dir: 'test',
49
49
  prefab_envs: ['unit_tests'],
50
- api_key: '123-development-yourapikey-SDK',
51
- collect_sync_interval: 1000 # we'll trigger sync manually in our test
50
+ api_key: '123-development-yourapikey-SDK'
52
51
  }.merge(overrides))
53
52
 
54
53
  Prefab::Client.new(options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.2
4
+ version: 0.23.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -232,6 +232,7 @@ files:
232
232
  - lib/prefab/errors/initialization_timeout_error.rb
233
233
  - lib/prefab/errors/invalid_api_key_error.rb
234
234
  - lib/prefab/errors/missing_default_error.rb
235
+ - lib/prefab/exponential_backoff.rb
235
236
  - lib/prefab/feature_flag_client.rb
236
237
  - lib/prefab/internal_logger.rb
237
238
  - lib/prefab/local_config_parser.rb
@@ -258,6 +259,7 @@ files:
258
259
  - test/test_config_resolver.rb
259
260
  - test/test_config_value_unwrapper.rb
260
261
  - test/test_criteria_evaluator.rb
262
+ - test/test_exponential_backoff.rb
261
263
  - test/test_feature_flag_client.rb
262
264
  - test/test_helper.rb
263
265
  - test/test_integration.rb