Class: LiveQA::Processor::Batch
- Inherits:
-
Object
- Object
- LiveQA::Processor::Batch
- Defined in:
- lib/liveqa/processor/batch.rb
Constant Summary collapse
- MAX_BYTES =
200Kb
204_800- MAX_MESSAGES =
100- MAX_MESSAGE_BYTES =
32Kb
32_768- MAX_RETRY =
10- RETRY_MAP =
{ 1 => 2, 2 => 5, 3 => 10, 4 => 20, 5 => 30, 6 => 30, 7 => 30, 8 => 30, 9 => 30, 10 => 30, }.freeze
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #<<(message) ⇒ Object
- #can_retry? ⇒ Boolean
- #can_run? ⇒ Boolean
- #full? ⇒ Boolean
-
#initialize ⇒ Batch
constructor
A new instance of Batch.
- #update_retry ⇒ Object
Constructor Details
#initialize ⇒ Batch
Returns a new instance of Batch.
25 26 27 28 29 |
# File 'lib/liveqa/processor/batch.rb', line 25 def initialize @retry_count = 0 @total_bytes = 0 = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'lib/liveqa/processor/batch.rb', line 5 def end |
Instance Method Details
#<<(message) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/liveqa/processor/batch.rb', line 31 def <<() = .to_json.bytesize if () LiveQA.configurations.logger.error('Message is too big to be send') return false end @total_bytes += << true end |
#can_retry? ⇒ Boolean
61 62 63 |
# File 'lib/liveqa/processor/batch.rb', line 61 def can_retry? @retry_count < MAX_RETRY end |
#can_run? ⇒ Boolean
55 56 57 58 59 |
# File 'lib/liveqa/processor/batch.rb', line 55 def can_run? return true if @retry_count.zero? Time.now >= @retry_at end |
#full? ⇒ Boolean
46 47 48 |
# File 'lib/liveqa/processor/batch.rb', line 46 def full? || max_size_reached? end |
#update_retry ⇒ Object
50 51 52 53 |
# File 'lib/liveqa/processor/batch.rb', line 50 def update_retry @retry_count += 1 @retry_at = Time.now + (RETRY_MAP[@retry_count] || 120) end |