Class: SagaForge::Dashboard::TimelinePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/saga_forge/dashboard/timeline_presenter.rb

Overview

One time-ordered stream for a saga instance: the event ledger merged with the compensation progress the engine records in context. The engine does not pre-merge these, so the dashboard owns it.

Defined Under Namespace

Classes: Entry

Constant Summary collapse

MAX_ENTRIES =

A stay-loop saga can accumulate thousands of event rows; rendering all of them (each with a full payload/backtrace) doesn't scale. Cap to the most recent MAX_ENTRIES, mirroring StatsQuery::CAP's spirit. Compensation entries are small (derived from context, not a separate table) and are never capped.

500

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ TimelinePresenter

Returns a new instance of TimelinePresenter.



22
23
24
# File 'app/presenters/saga_forge/dashboard/timeline_presenter.rb', line 22

def initialize(state)
  @state = state
end

Instance Method Details

#entriesObject



26
27
28
# File 'app/presenters/saga_forge/dashboard/timeline_presenter.rb', line 26

def entries
  @entries ||= event_entries + compensation_entries
end

#sortedObject



30
31
32
# File 'app/presenters/saga_forge/dashboard/timeline_presenter.rb', line 30

def sorted
  @sorted ||= entries.sort_by { |e| [e.at || Time.at(0), (e.kind == :event) ? 0 : 1, e.index] }
end

#total_event_countObject



39
# File 'app/presenters/saga_forge/dashboard/timeline_presenter.rb', line 39

def total_event_count = @total_event_count ||= @state.events.count

#truncated?Boolean

True when the event ledger was truncated to the most recent MAX_ENTRIES. Side-effect-free (derived from total_event_count alone) so it gives the right answer even if called before entries/sorted have run.

Returns:

  • (Boolean)


37
# File 'app/presenters/saga_forge/dashboard/timeline_presenter.rb', line 37

def truncated? = total_event_count > MAX_ENTRIES