Class: Sqreen::Deliveries::Batch

Inherits:
Simple
  • Object
show all
Defined in:
lib/sqreen/deliveries/batch.rb

Overview

Simple delivery method that batch event already seen in a batch

Instance Attribute Summary collapse

Attributes inherited from Simple

#session

Instance Method Summary collapse

Methods included from Log::Loggable

included, #logger

Constructor Details

#initialize(session, max_batch, max_staleness, randomize_staleness = true) ⇒ Batch

Returns a new instance of Batch.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sqreen/deliveries/batch.rb', line 26

def initialize(session,
               max_batch,
               max_staleness,
               randomize_staleness = true)
  super(session)
  self.max_batch = max_batch
  self.max_staleness = max_staleness
  @original_max_staleness = max_staleness
  self.current_batch = []
  @first_seen = {}
  @randomize_staleness = randomize_staleness
end

Instance Attribute Details

#current_batchObject

Returns the value of attribute current_batch.



24
25
26
# File 'lib/sqreen/deliveries/batch.rb', line 24

def current_batch
  @current_batch
end

#first_seenObject

Returns the value of attribute first_seen.



24
25
26
# File 'lib/sqreen/deliveries/batch.rb', line 24

def first_seen
  @first_seen
end

#max_batchObject

Returns the value of attribute max_batch.



23
24
25
# File 'lib/sqreen/deliveries/batch.rb', line 23

def max_batch
  @max_batch
end

#max_stalenessObject

Returns the value of attribute max_staleness.



23
24
25
# File 'lib/sqreen/deliveries/batch.rb', line 23

def max_staleness
  @max_staleness
end

Instance Method Details

#drainObject



44
45
46
# File 'lib/sqreen/deliveries/batch.rb', line 44

def drain
  post_batch unless current_batch.empty?
end

#post_event(event) ⇒ Object



39
40
41
42
# File 'lib/sqreen/deliveries/batch.rb', line 39

def post_event(event)
  current_batch.push(event)
  post_batch if post_batch_needed?(event)
end

#tickObject



48
49
50
# File 'lib/sqreen/deliveries/batch.rb', line 48

def tick
  post_batch if !current_batch.empty? && stale?
end