Class: Run

Inherits:
ApplicationRecord show all
Defined in:
app/models/run.rb

Constant Summary collapse

STATUSES =
%w[queued running needs_input succeeded failed cancelled].freeze
EXHAUSTION =

A budget/timeout outcome, whether the segment parked (needs_input) or was recorded as a failure. The parked message ("…turn budget mid-work…") lives on the last question event; the failure message (failure_reason) lives on result_summary. Either signals "try again with a fresh budget," not a bug.

/turn budget|max-turns budget|timed out|timeout/i

Instance Method Summary collapse

Instance Method Details

#exhausted?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'app/models/run.rb', line 19

def exhausted?
  text = needs_input? ? events.where(kind: "question").order(:id).last&.text : result_summary
  text.to_s.match?(EXHAUSTION)
end

#finished?Boolean

Returns:

  • (Boolean)


17
# File 'app/models/run.rb', line 17

def finished? = %w[succeeded failed cancelled].include?(status)

#restartable?Boolean

A run the user can relaunch from the work panel: an execution-column run that parked or failed on its budget/timeout. Restart resumes the surviving session (fresh budget) or starts a clean run when no session remains.

Returns:

  • (Boolean)


27
# File 'app/models/run.rb', line 27

def restartable? = card.column.execution? && (needs_input? || failed?) && exhausted?