Class: Karafka::Core::Monitoring::Event
- Inherits:
-
Object
- Object
- Karafka::Core::Monitoring::Event
- Defined in:
- lib/karafka/core/monitoring/event.rb
Overview
Single notification event wrapping payload with id
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Hash access to the payload data (if present) Provides direct access to time without triggering payload hash construction.
-
#initialize(id, payload, time = nil) ⇒ Event
constructor
A new instance of Event.
-
#payload ⇒ Hash
Full payload including time (if set).
Constructor Details
#initialize(id, payload, time = nil) ⇒ Event
Returns a new instance of Event.
14 15 16 17 18 19 |
# File 'lib/karafka/core/monitoring/event.rb', line 14 def initialize(id, payload, time = nil) @id = id @raw_payload = payload @time = time @payload = nil end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/karafka/core/monitoring/event.rb', line 8 def id @id end |
Instance Method Details
#[](name) ⇒ Object
Hash access to the payload data (if present) Provides direct access to time without triggering payload hash construction.
35 36 37 38 39 |
# File 'lib/karafka/core/monitoring/event.rb', line 35 def [](name) return @time if name == :time && @time @raw_payload.fetch(name) end |
#payload ⇒ Hash
Returns full payload including time (if set). The merged hash is built lazily on first access to avoid allocating a new Hash when listeners only use ‘#[]`.
23 24 25 26 27 28 29 |
# File 'lib/karafka/core/monitoring/event.rb', line 23 def payload @payload ||= if @time @raw_payload.empty? ? { time: @time } : @raw_payload.merge(time: @time) else @raw_payload end end |