Class: Prefab::ConfigClient
- Inherits:
-
Object
- Object
- Prefab::ConfigClient
- Defined in:
- lib/prefab/config_client.rb
Constant Summary collapse
- RECONNECT_WAIT =
5- DEFAULT_CHECKPOINT_FREQ_SEC =
60- SSE_READ_TIMEOUT =
300- STALE_CACHE_WARN_HOURS =
5- AUTH_USER =
'authuser'- LOGGING_KEY_PREFIX =
"#{Prefab::LoggerClient::BASE_KEY}#{Prefab::LoggerClient::SEP}".freeze
- LOG =
Prefab::InternalLogger.new(ConfigClient)
Class Method Summary collapse
Instance Method Summary collapse
- #get(key, default = NO_DEFAULT_PROVIDED, properties = NO_DEFAULT_PROVIDED) ⇒ Object
-
#initialize(base_client, timeout) ⇒ ConfigClient
constructor
A new instance of ConfigClient.
- #resolver ⇒ Object
- #start_streaming ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(base_client, timeout) ⇒ ConfigClient
Returns a new instance of ConfigClient.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prefab/config_client.rb', line 13 def initialize(base_client, timeout) @base_client = base_client @options = base_client. LOG.debug 'Initialize ConfigClient' @timeout = timeout @stream_lock = Concurrent::ReadWriteLock.new @checkpoint_freq_secs = DEFAULT_CHECKPOINT_FREQ_SEC @config_loader = Prefab::ConfigLoader.new(@base_client) @config_resolver = Prefab::ConfigResolver.new(@base_client, @config_loader) @initialization_lock = Concurrent::ReadWriteLock.new LOG.debug 'Initialize ConfigClient: AcquireWriteLock' @initialization_lock.acquire_write_lock LOG.debug 'Initialize ConfigClient: AcquiredWriteLock' @initialized_future = Concurrent::Future.execute { @initialization_lock.acquire_read_lock } if @options.local_only? finish_init!(:local_only, nil) else load_checkpoint start_checkpointing_thread start_streaming end end |
Class Method Details
.value_to_delta(key, config_value, namespace = nil) ⇒ Object
55 56 57 58 |
# File 'lib/prefab/config_client.rb', line 55 def self.value_to_delta(key, config_value, namespace = nil) PrefabProto::Config.new(key: [namespace, key].compact.join(':'), rows: [PrefabProto::ConfigRow.new(value: config_value)]) end |
Instance Method Details
#get(key, default = NO_DEFAULT_PROVIDED, properties = NO_DEFAULT_PROVIDED) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/prefab/config_client.rb', line 60 def get(key, default = NO_DEFAULT_PROVIDED, properties = NO_DEFAULT_PROVIDED) context = @config_resolver.make_context(properties) if !context.blank? && @base_client.example_contexts_aggregator @base_client.example_contexts_aggregator.record(context) end evaluation = _get(key, context) @base_client.context_shape_aggregator&.push(context) if evaluation evaluation.report_and_return(@base_client.evaluation_summary_aggregator) else handle_default(key, default) end end |
#resolver ⇒ Object
51 52 53 |
# File 'lib/prefab/config_client.rb', line 51 def resolver @config_resolver end |
#start_streaming ⇒ Object
41 42 43 44 45 |
# File 'lib/prefab/config_client.rb', line 41 def start_streaming @stream_lock.with_write_lock do start_sse_streaming_connection_thread(@config_loader.highwater_mark) if @streaming_thread.nil? end end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/prefab/config_client.rb', line 47 def to_s @config_resolver.to_s end |