Class: Ace::Assign::Models::Step
- Inherits:
-
Object
- Object
- Ace::Assign::Models::Step
- Defined in:
- lib/ace/assign/models/step.rb
Overview
Step data model representing a work queue item.
Pure data carrier with no business logic (ATOM pattern). All attributes are immutable after initialization.
Constant Summary collapse
- STATUSES =
Valid status values
%i[pending in_progress done failed].freeze
- VALID_CONTEXTS =
Valid context values for execution context
%w[fork].freeze
Instance Attribute Summary collapse
-
#added_by ⇒ Object
readonly
Returns the value of attribute added_by.
-
#batch_parent ⇒ Object
readonly
Returns the value of attribute batch_parent.
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#fork_launch_pid ⇒ Object
readonly
Returns the value of attribute fork_launch_pid.
-
#fork_options ⇒ Object
readonly
Returns the value of attribute fork_options.
-
#fork_pid_file ⇒ Object
readonly
Returns the value of attribute fork_pid_file.
-
#fork_pid_updated_at ⇒ Object
readonly
Returns the value of attribute fork_pid_updated_at.
-
#fork_retry_limit ⇒ Object
readonly
Returns the value of attribute fork_retry_limit.
-
#fork_tracked_pids ⇒ Object
readonly
Returns the value of attribute fork_tracked_pids.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#max_parallel ⇒ Object
readonly
Returns the value of attribute max_parallel.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#parallel ⇒ Object
readonly
Returns the value of attribute parallel.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#skill ⇒ Object
readonly
Returns the value of attribute skill.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#stall_reason ⇒ Object
readonly
Returns the value of attribute stall_reason.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Check if step is complete (done or failed).
-
#fork? ⇒ Boolean
Check if this step should run in a forked context (subagent).
-
#fork_provider ⇒ String?
Resolve per-step provider override from fork options.
-
#initialize(number:, name:, status:, instructions:, report: nil, error: nil, started_at: nil, completed_at: nil, added_by: nil, parent: nil, file_path: nil, source: nil, skill: nil, workflow: nil, context: nil, batch_parent: nil, parallel: nil, max_parallel: nil, fork_retry_limit: nil, fork_options: nil, fork_launch_pid: nil, fork_tracked_pids: nil, fork_pid_updated_at: nil, fork_pid_file: nil, stall_reason: nil) ⇒ Step
constructor
A new instance of Step.
-
#retry? ⇒ Boolean
Check if this is a retry of another step.
-
#retry_of ⇒ String?
Get the original step number if this is a retry.
-
#to_display_row ⇒ Hash
Convert to display row for status table.
-
#to_frontmatter ⇒ Hash
Convert to frontmatter hash for YAML serialization.
-
#workable? ⇒ Boolean
Check if step can be worked on.
Constructor Details
#initialize(number:, name:, status:, instructions:, report: nil, error: nil, started_at: nil, completed_at: nil, added_by: nil, parent: nil, file_path: nil, source: nil, skill: nil, workflow: nil, context: nil, batch_parent: nil, parallel: nil, max_parallel: nil, fork_retry_limit: nil, fork_options: nil, fork_launch_pid: nil, fork_tracked_pids: nil, fork_pid_updated_at: nil, fork_pid_file: nil, stall_reason: nil) ⇒ Step
Returns a new instance of Step.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ace/assign/models/step.rb', line 55 def initialize(number:, name:, status:, instructions:, report: nil, error: nil, started_at: nil, completed_at: nil, added_by: nil, parent: nil, file_path: nil, source: nil, skill: nil, workflow: nil, context: nil, batch_parent: nil, parallel: nil, max_parallel: nil, fork_retry_limit: nil, fork_options: nil, fork_launch_pid: nil, fork_tracked_pids: nil, fork_pid_updated_at: nil, fork_pid_file: nil, stall_reason: nil) validate_status!(status) validate_context!(context) if context validate_boolean!(:batch_parent, batch_parent) validate_boolean!(:parallel, parallel) validate_positive_integer!(:max_parallel, max_parallel) validate_non_negative_integer!(:fork_retry_limit, fork_retry_limit) validate_hash!(:fork_options, ) @number = number.freeze @name = name.freeze @status = status @instructions = instructions.freeze @report = report&.freeze @error = error&.freeze @started_at = started_at @completed_at = completed_at @added_by = added_by&.freeze @parent = parent&.freeze @file_path = file_path&.freeze @source = source&.freeze @skill = skill&.freeze @workflow = workflow&.freeze @context = context&.freeze @batch_parent = batch_parent.nil? ? nil : !!batch_parent @parallel = parallel.nil? ? nil : !!parallel @max_parallel = max_parallel&.to_i @fork_retry_limit = fork_retry_limit&.to_i @fork_options = () @fork_launch_pid = fork_launch_pid&.to_i @fork_tracked_pids = Array(fork_tracked_pids).map(&:to_i).uniq.sort.freeze @fork_pid_updated_at = fork_pid_updated_at @fork_pid_file = fork_pid_file&.freeze @stall_reason = stall_reason&.freeze end |
Instance Attribute Details
#added_by ⇒ Object (readonly)
Returns the value of attribute added_by.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def added_by @added_by end |
#batch_parent ⇒ Object (readonly)
Returns the value of attribute batch_parent.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def batch_parent @batch_parent end |
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def completed_at @completed_at end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def context @context end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def error @error end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def file_path @file_path end |
#fork_launch_pid ⇒ Object (readonly)
Returns the value of attribute fork_launch_pid.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def fork_launch_pid @fork_launch_pid end |
#fork_options ⇒ Object (readonly)
Returns the value of attribute fork_options.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def @fork_options end |
#fork_pid_file ⇒ Object (readonly)
Returns the value of attribute fork_pid_file.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def fork_pid_file @fork_pid_file end |
#fork_pid_updated_at ⇒ Object (readonly)
Returns the value of attribute fork_pid_updated_at.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def fork_pid_updated_at @fork_pid_updated_at end |
#fork_retry_limit ⇒ Object (readonly)
Returns the value of attribute fork_retry_limit.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def fork_retry_limit @fork_retry_limit end |
#fork_tracked_pids ⇒ Object (readonly)
Returns the value of attribute fork_tracked_pids.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def fork_tracked_pids @fork_tracked_pids end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def instructions @instructions end |
#max_parallel ⇒ Object (readonly)
Returns the value of attribute max_parallel.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def max_parallel @max_parallel end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def number @number end |
#parallel ⇒ Object (readonly)
Returns the value of attribute parallel.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def parallel @parallel end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def parent @parent end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def report @report end |
#skill ⇒ Object (readonly)
Returns the value of attribute skill.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def skill @skill end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def source @source end |
#stall_reason ⇒ Object (readonly)
Returns the value of attribute stall_reason.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def stall_reason @stall_reason end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def started_at @started_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def status @status end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
25 26 27 |
# File 'lib/ace/assign/models/step.rb', line 25 def workflow @workflow end |
Instance Method Details
#complete? ⇒ Boolean
Check if step is complete (done or failed)
99 100 101 |
# File 'lib/ace/assign/models/step.rb', line 99 def complete? %i[done failed].include?(status) end |
#fork? ⇒ Boolean
Check if this step should run in a forked context (subagent)
117 118 119 |
# File 'lib/ace/assign/models/step.rb', line 117 def fork? context == "fork" end |
#fork_provider ⇒ String?
Resolve per-step provider override from fork options.
123 124 125 126 127 128 129 |
# File 'lib/ace/assign/models/step.rb', line 123 def fork_provider return nil unless provider = ["provider"] provider = provider.to_s.strip provider.empty? ? nil : provider end |
#retry? ⇒ Boolean
Check if this is a retry of another step
111 112 113 |
# File 'lib/ace/assign/models/step.rb', line 111 def retry? added_by&.start_with?("retry_of:") end |
#retry_of ⇒ String?
Get the original step number if this is a retry
133 134 135 136 137 |
# File 'lib/ace/assign/models/step.rb', line 133 def retry_of return nil unless retry? added_by.sub("retry_of:", "") end |
#to_display_row ⇒ Hash
Convert to display row for status table
169 170 171 172 173 174 175 176 |
# File 'lib/ace/assign/models/step.rb', line 169 def to_display_row { file: File.basename(file_path || "#{number}-#{name}.st.md"), status: status.to_s, name: name, error: error } end |
#to_frontmatter ⇒ Hash
Convert to frontmatter hash for YAML serialization
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ace/assign/models/step.rb', line 141 def to_frontmatter { "name" => name, "status" => status.to_s, "source" => source, "skill" => skill, "workflow" => workflow, "context" => context, "batch_parent" => batch_parent, "parallel" => parallel, "max_parallel" => max_parallel, "fork_retry_limit" => fork_retry_limit, "fork" => , "started_at" => started_at&.iso8601, "completed_at" => completed_at&.iso8601, "fork_launch_pid" => fork_launch_pid, "fork_tracked_pids" => fork_tracked_pids, "fork_pid_updated_at" => fork_pid_updated_at&.iso8601, "fork_pid_file" => fork_pid_file, "error" => error, "stall_reason" => stall_reason, "added_by" => added_by, "parent" => parent }.compact end |
#workable? ⇒ Boolean
Check if step can be worked on
105 106 107 |
# File 'lib/ace/assign/models/step.rb', line 105 def workable? status == :pending || status == :in_progress end |