Class: Statsig::SpecStore
- Inherits:
-
Object
- Object
- Statsig::SpecStore
- Defined in:
- lib/spec_store.rb
Constant Summary collapse
- CONFIG_SPECS_KEY =
"statsig.cache"
Instance Attribute Summary collapse
-
#init_reason ⇒ Object
Returns the value of attribute init_reason.
-
#initial_config_sync_time ⇒ Object
Returns the value of attribute initial_config_sync_time.
-
#last_config_sync_time ⇒ Object
Returns the value of attribute last_config_sync_time.
Instance Method Summary collapse
- #get_config(config_name) ⇒ Object
- #get_gate(gate_name) ⇒ Object
- #get_id_list(list_name) ⇒ Object
- #get_layer(layer_name) ⇒ Object
- #get_raw_specs ⇒ Object
- #has_config?(config_name) ⇒ Boolean
- #has_gate?(gate_name) ⇒ Boolean
- #has_layer?(layer_name) ⇒ Boolean
-
#initialize(network, options, error_callback, init_diagnostics = nil) ⇒ SpecStore
constructor
A new instance of SpecStore.
- #is_ready_for_checks ⇒ Object
- #maybe_restart_background_threads ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(network, options, error_callback, init_diagnostics = nil) ⇒ SpecStore
Returns a new instance of SpecStore.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/spec_store.rb', line 17 def initialize(network, , error_callback, init_diagnostics = nil) @init_reason = EvaluationReason::UNINITIALIZED @network = network @options = @error_callback = error_callback @last_config_sync_time = 0 @initial_config_sync_time = 0 @rulesets_sync_interval = .rulesets_sync_interval @id_lists_sync_interval = .idlists_sync_interval @rules_updated_callback = .rules_updated_callback @specs = { :gates => {}, :configs => {}, :layers => {}, :id_lists => {}, :experiment_to_layer => {} } @id_list_thread_pool = Concurrent::FixedThreadPool.new( .idlist_threadpool_size, max_queue: 100, fallback_policy: :discard, ) unless @options.bootstrap_values.nil? begin if !@options.data_store.nil? puts 'data_store gets priority over bootstrap_values. bootstrap_values will be ignored' else init_diagnostics&.mark("bootstrap", "start", "load") if process(.bootstrap_values) @init_reason = EvaluationReason::BOOTSTRAP end init_diagnostics&.mark("bootstrap", "end", "load", @init_reason == EvaluationReason::BOOTSTRAP) end rescue puts 'the provided bootstrapValues is not a valid JSON string' end end unless @options.data_store.nil? init_diagnostics&.mark("data_store", "start", "load") @options.data_store.init load_from_storage_adapter init_diagnostics&.mark("data_store", "end", "load", @init_reason == EvaluationReason::DATA_ADAPTER) end if @init_reason == EvaluationReason::UNINITIALIZED download_config_specs(init_diagnostics) end @initial_config_sync_time = @last_config_sync_time == 0 ? -1 : @last_config_sync_time get_id_lists(init_diagnostics) @config_sync_thread = sync_config_specs @id_lists_sync_thread = sync_id_lists end |
Instance Attribute Details
#init_reason ⇒ Object
Returns the value of attribute init_reason.
15 16 17 |
# File 'lib/spec_store.rb', line 15 def init_reason @init_reason end |
#initial_config_sync_time ⇒ Object
Returns the value of attribute initial_config_sync_time.
14 15 16 |
# File 'lib/spec_store.rb', line 14 def initial_config_sync_time @initial_config_sync_time end |
#last_config_sync_time ⇒ Object
Returns the value of attribute last_config_sync_time.
13 14 15 |
# File 'lib/spec_store.rb', line 13 def last_config_sync_time @last_config_sync_time end |
Instance Method Details
#get_config(config_name) ⇒ Object
106 107 108 109 |
# File 'lib/spec_store.rb', line 106 def get_config(config_name) return nil unless has_config?(config_name) @specs[:configs][config_name] end |
#get_gate(gate_name) ⇒ Object
101 102 103 104 |
# File 'lib/spec_store.rb', line 101 def get_gate(gate_name) return nil unless has_gate?(gate_name) @specs[:gates][gate_name] end |
#get_id_list(list_name) ⇒ Object
116 117 118 |
# File 'lib/spec_store.rb', line 116 def get_id_list(list_name) @specs[:id_lists][list_name] end |
#get_layer(layer_name) ⇒ Object
111 112 113 114 |
# File 'lib/spec_store.rb', line 111 def get_layer(layer_name) return nil unless has_layer?(layer_name) @specs[:layers][layer_name] end |
#get_raw_specs ⇒ Object
120 121 122 |
# File 'lib/spec_store.rb', line 120 def get_raw_specs @specs end |
#has_config?(config_name) ⇒ Boolean
93 94 95 |
# File 'lib/spec_store.rb', line 93 def has_config?(config_name) @specs[:configs].key?(config_name) end |
#has_gate?(gate_name) ⇒ Boolean
89 90 91 |
# File 'lib/spec_store.rb', line 89 def has_gate?(gate_name) @specs[:gates].key?(gate_name) end |
#has_layer?(layer_name) ⇒ Boolean
97 98 99 |
# File 'lib/spec_store.rb', line 97 def has_layer?(layer_name) @specs[:layers].key?(layer_name) end |
#is_ready_for_checks ⇒ Object
75 76 77 |
# File 'lib/spec_store.rb', line 75 def is_ready_for_checks @last_config_sync_time != 0 end |
#maybe_restart_background_threads ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/spec_store.rb', line 124 def maybe_restart_background_threads if @config_sync_thread.nil? or !@config_sync_thread.alive? @config_sync_thread = sync_config_specs end if @id_lists_sync_thread.nil? or !@id_lists_sync_thread.alive? @id_lists_sync_thread = sync_id_lists end end |
#shutdown ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/spec_store.rb', line 79 def shutdown @config_sync_thread&.exit @id_lists_sync_thread&.exit @id_list_thread_pool.shutdown @id_list_thread_pool.wait_for_termination(timeout = 3) unless @options.data_store.nil? @options.data_store.shutdown end end |