Class: OpenLoam::EventDelivery

Inherits:
TenantRecord
  • Object
show all
Defined in:
app/models/open_loam/event_delivery.rb

Overview

One durable delivery of one event to one persistent subscriber (see OpenLoam::DurableEvents). The ROW is the durable record of intent: it is committed in the event's tenant at publish time, and the background job is only an accelerator. If the job is lost, the sweep re-enqueues from this row.

Lifecycle: pending -> delivered (handler ran) | dead (handler removed, or MAX_ATTEMPTS exhausted). A pending row with next_attempt_at in the future is simply waiting out its backoff.

Constant Summary collapse

STATUSES =
%w[pending delivered dead].freeze

Instance Method Summary collapse

Instance Method Details

#payload_hash ⇒ Object

The stored payload as a Hash regardless of adapter (Postgres jsonb returns a Hash; a text/json column may hand back a String).



29
30
31
32
33
34
35
36
# File 'app/models/open_loam/event_delivery.rb', line 29

def payload_hash
  value = self[:payload]
  return value if value.is_a?(Hash)

  JSON.parse(value.to_s.presence || "{}")
rescue JSON::ParserError
  {}
end