Class: PostHog::MessageBatch
- Inherits:
-
Object
- Object
- PostHog::MessageBatch
- Extended by:
- Forwardable
- Includes:
- Defaults::MessageBatch, Logging
- Defined in:
- lib/posthog/message_batch.rb
Overview
A batch of ‘Message`s to be sent to the API
Defined Under Namespace
Classes: JSONGenerationError
Constant Summary
Constants included from Defaults::MessageBatch
Defaults::MessageBatch::MAX_BYTES, Defaults::MessageBatch::MAX_SIZE
Instance Method Summary collapse
- #<<(message) ⇒ Object
- #clear ⇒ Object
- #full? ⇒ Boolean
-
#initialize(max_message_count) ⇒ MessageBatch
constructor
A new instance of MessageBatch.
Methods included from Logging
Constructor Details
#initialize(max_message_count) ⇒ MessageBatch
Returns a new instance of MessageBatch.
16 17 18 19 20 |
# File 'lib/posthog/message_batch.rb', line 16 def initialize() = [] = @json_size = 0 end |
Instance Method Details
#<<(message) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/posthog/message_batch.rb', line 22 def <<() begin = .to_json rescue StandardError => e raise JSONGenerationError, "Serialization error: #{e}" end = .bytesize if () logger.error('a message exceeded the maximum allowed size') else << @json_size += + 1 # One byte for the comma end end |
#clear ⇒ Object
42 43 44 45 |
# File 'lib/posthog/message_batch.rb', line 42 def clear .clear @json_size = 0 end |
#full? ⇒ Boolean
38 39 40 |
# File 'lib/posthog/message_batch.rb', line 38 def full? item_count_exhausted? || size_exhausted? end |