Class: ChronoForge::Dashboard::WaitStatePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/chrono_forge/dashboard/wait_state_presenter.rb

Defined Under Namespace

Classes: Active

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow) ⇒ WaitStatePresenter

Returns a new instance of WaitStatePresenter.



26
# File 'app/presenters/chrono_forge/dashboard/wait_state_presenter.rb', line 26

def initialize(workflow) = @workflow = workflow

Class Method Details

.active_map(workflows) ⇒ Object

Active waits for a batch of workflows, in two queries instead of one per row. Returns => Active for idle workflows currently parked on a pending wait_until or continue_if. Bounded by the caller’s set.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/presenters/chrono_forge/dashboard/wait_state_presenter.rb', line 38

def self.active_map(workflows)
  ids = workflows.select(&:idle?).map(&:id)
  return {} if ids.empty?

  d = StepNameParser::DELIM
  latest = {}
  ChronoForge::ExecutionLog
    .where(workflow_id: ids, state: ChronoForge::ExecutionLog.states[:pending])
    .where("step_name LIKE ? OR step_name LIKE ?", "wait_until#{d}%", "continue_if#{d}%")
    .order(Arel.sql("started_at, id"))
    .each { |log| latest[log.workflow_id] = log }

  latest.transform_values { |log| build(log) }
end

.build(log) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'app/presenters/chrono_forge/dashboard/wait_state_presenter.rb', line 53

def self.build(log)
  p = StepNameParser.parse(log.step_name)
  Active.new(
    kind: p.kind,
    condition: p.name,
    waiting_since: log.last_executed_at || log.started_at,
    timeout_at: log.&.dig("timeout_at")
  )
end

Instance Method Details

#activeObject

Reuses the batch resolver so a single workflow and a page of them agree: it looks at the latest *pending wait/continue* log, ignoring durably_repeat run logs (which stamp started_at = now and would otherwise mask the wait).



31
32
33
# File 'app/presenters/chrono_forge/dashboard/wait_state_presenter.rb', line 31

def active
  self.class.active_map([@workflow])[@workflow.id]
end