Class: LaunchDarkly::EventProcessor
- Inherits:
-
Object
- Object
- LaunchDarkly::EventProcessor
- Includes:
- EventProcessorMethods
- Defined in:
- lib/ldclient-rb/events.rb
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(sdk_key, config, client = nil, diagnostic_accumulator = nil, test_properties = nil) ⇒ EventProcessor
constructor
A new instance of EventProcessor.
- #record_alias_event(user, previous_user) ⇒ Object
- #record_custom_event(user, key, data = nil, metric_value = nil) ⇒ Object
- #record_eval_event(user, key, version = nil, variation = nil, value = nil, reason = nil, default = nil, track_events = false, debug_until = nil, prereq_of = nil) ⇒ Object
- #record_identify_event(user) ⇒ Object
- #stop ⇒ Object
-
#wait_until_inactive ⇒ Object
exposed only for testing.
Constructor Details
#initialize(sdk_key, config, client = nil, diagnostic_accumulator = nil, test_properties = nil) ⇒ EventProcessor
Returns a new instance of EventProcessor.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ldclient-rb/events.rb', line 118 def initialize(sdk_key, config, client = nil, diagnostic_accumulator = nil, test_properties = nil) raise ArgumentError, "sdk_key must not be nil" if sdk_key.nil? # see LDClient constructor comment on sdk_key @logger = config.logger @inbox = SizedQueue.new(config.capacity < 100 ? 100 : config.capacity) @flush_task = Concurrent::TimerTask.new(execution_interval: config.flush_interval) do post_to_inbox(FlushMessage.new) end @flush_task.execute @users_flush_task = Concurrent::TimerTask.new(execution_interval: config.user_keys_flush_interval) do post_to_inbox(FlushUsersMessage.new) end @users_flush_task.execute if !diagnostic_accumulator.nil? interval = test_properties && test_properties.has_key?(:diagnostic_recording_interval) ? test_properties[:diagnostic_recording_interval] : config.diagnostic_recording_interval @diagnostic_event_task = Concurrent::TimerTask.new(execution_interval: interval) do post_to_inbox(DiagnosticEventMessage.new) end @diagnostic_event_task.execute else @diagnostic_event_task = nil end @stopped = Concurrent::AtomicBoolean.new(false) @inbox_full = Concurrent::AtomicBoolean.new(false) event_sender = (test_properties || {})[:event_sender] || Impl::EventSender.new(sdk_key, config, client ? client : Util.new_http_client(config.events_uri, config)) = (test_properties || {})[:timestamp_fn] || proc { Impl::Util.current_time_millis } EventDispatcher.new(@inbox, sdk_key, config, diagnostic_accumulator, event_sender) end |
Instance Method Details
#flush ⇒ Object
186 187 188 189 |
# File 'lib/ldclient-rb/events.rb', line 186 def flush # flush is done asynchronously post_to_inbox(FlushMessage.new) end |
#record_alias_event(user, previous_user) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'lib/ldclient-rb/events.rb', line 176 def record_alias_event(user, previous_user) post_to_inbox(LaunchDarkly::Impl::AliasEvent.new( , user.nil? ? nil : user[:key], user_to_context_kind(user), previous_user.nil? ? nil : previous_user[:key], user_to_context_kind(previous_user) )) end |
#record_custom_event(user, key, data = nil, metric_value = nil) ⇒ Object
172 173 174 |
# File 'lib/ldclient-rb/events.rb', line 172 def record_custom_event(user, key, data = nil, metric_value = nil) post_to_inbox(LaunchDarkly::Impl::CustomEvent.new(, user, key, data, metric_value)) end |
#record_eval_event(user, key, version = nil, variation = nil, value = nil, reason = nil, default = nil, track_events = false, debug_until = nil, prereq_of = nil) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ldclient-rb/events.rb', line 152 def record_eval_event( user, key, version = nil, variation = nil, value = nil, reason = nil, default = nil, track_events = false, debug_until = nil, prereq_of = nil ) post_to_inbox(LaunchDarkly::Impl::EvalEvent.new(, user, key, version, variation, value, reason, default, track_events, debug_until, prereq_of)) end |
#record_identify_event(user) ⇒ Object
168 169 170 |
# File 'lib/ldclient-rb/events.rb', line 168 def record_identify_event(user) post_to_inbox(LaunchDarkly::Impl::IdentifyEvent.new(, user)) end |
#stop ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/ldclient-rb/events.rb', line 191 def stop # final shutdown, which includes a final flush, is done synchronously if @stopped.make_true @flush_task.shutdown @users_flush_task.shutdown @diagnostic_event_task.shutdown if !@diagnostic_event_task.nil? # Note that here we are not calling post_to_inbox, because we *do* want to wait if the inbox # is full; an orderly shutdown can't happen unless these messages are received. @inbox << FlushMessage.new stop_msg = StopMessage.new @inbox << stop_msg stop_msg.wait_for_completion end end |
#wait_until_inactive ⇒ Object
exposed only for testing
207 208 209 210 211 |
# File 'lib/ldclient-rb/events.rb', line 207 def wait_until_inactive sync_msg = TestSyncMessage.new @inbox << sync_msg sync_msg.wait_for_completion end |