Class: LaunchDarkly::EventProcessor
- Inherits:
-
Object
- Object
- LaunchDarkly::EventProcessor
- Defined in:
- lib/ldclient-rb/events.rb
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #flush ⇒ Object
-
#initialize(sdk_key, config) ⇒ EventProcessor
constructor
A new instance of EventProcessor.
Constructor Details
#initialize(sdk_key, config) ⇒ EventProcessor
Returns a new instance of EventProcessor.
7 8 9 10 11 12 13 |
# File 'lib/ldclient-rb/events.rb', line 7 def initialize(sdk_key, config) @queue = Queue.new @sdk_key = sdk_key @config = config @client = Faraday.new @worker = create_worker end |
Instance Method Details
#add_event(event) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ldclient-rb/events.rb', line 56 def add_event(event) return if @offline if @queue.length < @config.capacity event[:creationDate] = (Time.now.to_f * 1000).to_i @config.logger.debug("[LDClient] Enqueueing event: #{event.to_json}") @queue.push(event) if !@worker.alive? @worker = create_worker end else @config.logger.warn("[LDClient] Exceeded event queue capacity. Increase capacity to avoid dropping events.") end end |
#flush ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ldclient-rb/events.rb', line 42 def flush events = [] begin loop do events << @queue.pop(true) end rescue ThreadError end if !events.empty? post_flushed_events(events) end end |