class Hawkei::Processor::Batch
Constants
- DEFAULT_RETRY_TIME
- MAX_BYTES
- MAX_MESSAGES
- MAX_MESSAGE_BYTES
- MAX_RETRY
- RETRY_MAP
Attributes
messages[R]
Public Class Methods
new()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 27 def initialize @retry_count = 0 @total_bytes = 0 @messages = [] end
Public Instance Methods
<<(message)
click to toggle source
# File lib/hawkei/processor/batch.rb, line 33 def <<(message) message_json_size = message.to_json.bytesize if max_message_reached?(message_json_size) Hawkei.configurations.logger.error('Message is too big to be send') return false end @total_bytes += message_json_size @messages << message true end
can_retry?()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 64 def can_retry? @retry_count < MAX_RETRY end
empty?()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 48 def empty? @messages.size.zero? end
full?()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 52 def full? max_messages_reached? || max_size_reached? end
next_retry()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 56 def next_retry RETRY_MAP[@retry_count] || DEFAULT_RETRY_TIME end
update_retry()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 60 def update_retry @retry_count += 1 end
Private Instance Methods
max_message_reached?(message_json_size)
click to toggle source
# File lib/hawkei/processor/batch.rb, line 78 def max_message_reached?(message_json_size) message_json_size > MAX_MESSAGE_BYTES end
max_messages_reached?()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 70 def max_messages_reached? @messages.length >= MAX_MESSAGES end
max_size_reached?()
click to toggle source
# File lib/hawkei/processor/batch.rb, line 74 def max_size_reached? @total_bytes >= MAX_BYTES end