Class: Journaled::Outbox::Event

Inherits:
Object
  • Object
show all
Defined in:
app/models/journaled/outbox/event.rb

Overview

ActiveRecord model for Outbox-style event processing

This model is only used when the Outbox::Adapter is configured. Events are stored in the database and processed by worker daemons.

Successfully delivered events are deleted immediately. Failed events are marked with failed_at and can be queried or requeued.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch_batch_for_updateArray<Journaled::Outbox::Event>

Fetch a batch of events for processing using SELECT FOR UPDATE

Returns:



33
34
35
36
37
38
# File 'app/models/journaled/outbox/event.rb', line 33

def self.fetch_batch_for_update
  ready_to_process
    .limit(Journaled.worker_batch_size)
    .lock
    .to_a
end

.oldest_non_failed_timestampTime?

Get the oldest non-failed event’s timestamp

Returns:

  • (Time, nil)

    The timestamp of the oldest event, or nil if no events exist



55
56
57
# File 'app/models/journaled/outbox/event.rb', line 55

def self.oldest_non_failed_timestamp
  ready_to_process.order(:id).limit(1).pick(:created_at)
end

Instance Method Details

#requeue!Boolean

Requeue a failed event for processing

Clears failure information so the event can be retried.

Returns:

  • (Boolean)

    Whether the requeue was successful



45
46
47
48
49
50
# File 'app/models/journaled/outbox/event.rb', line 45

def requeue!
  update!(
    failed_at: nil,
    failure_reason: nil,
  )
end