Class: Seekmodo::Sdk::Events::EventsQueue
- Inherits:
-
Object
- Object
- Seekmodo::Sdk::Events::EventsQueue
- Defined in:
- lib/seekmodo/sdk/events/events_queue.rb
Constant Summary collapse
- DEFAULT_AUTO_FLUSH_THRESHOLD =
50- DEFAULT_MAX_PER_FLUSH =
200
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(client, store, auto_flush_threshold: DEFAULT_AUTO_FLUSH_THRESHOLD, max_per_flush: DEFAULT_MAX_PER_FLUSH) ⇒ EventsQueue
constructor
A new instance of EventsQueue.
- #pending_count ⇒ Object
- #push(event) ⇒ Object
Constructor Details
#initialize(client, store, auto_flush_threshold: DEFAULT_AUTO_FLUSH_THRESHOLD, max_per_flush: DEFAULT_MAX_PER_FLUSH) ⇒ EventsQueue
Returns a new instance of EventsQueue.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/seekmodo/sdk/events/events_queue.rb', line 13 def initialize( client, store, auto_flush_threshold: DEFAULT_AUTO_FLUSH_THRESHOLD, max_per_flush: DEFAULT_MAX_PER_FLUSH ) @client = client @store = store @auto_flush_threshold = auto_flush_threshold @max_per_flush = max_per_flush end |
Instance Method Details
#flush ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/seekmodo/sdk/events/events_queue.rb', line 30 def flush batch = @store.drain(@max_per_flush) return 0 if batch.empty? begin @client.events(batch) rescue StandardError batch.each { |event| @store.push(event) } return 0 end batch.length end |
#pending_count ⇒ Object
44 45 46 |
# File 'lib/seekmodo/sdk/events/events_queue.rb', line 44 def pending_count @store.count end |
#push(event) ⇒ Object
25 26 27 28 |
# File 'lib/seekmodo/sdk/events/events_queue.rb', line 25 def push(event) @store.push(event) flush if @store.count >= @auto_flush_threshold end |