Class: RosettAi::Workflow::Steps::ShellStep
- Inherits:
-
Object
- Object
- RosettAi::Workflow::Steps::ShellStep
- Defined in:
- lib/rosett_ai/workflow/steps/shell_step.rb
Overview
Executes a shell command in array-form (no string interpolation).
Instance Method Summary collapse
-
#describe ⇒ String
Step description for dry-run.
-
#execute ⇒ Hash
Executes the shell command.
-
#initialize(definition) ⇒ ShellStep
constructor
A new instance of ShellStep.
Constructor Details
#initialize(definition) ⇒ ShellStep
Returns a new instance of ShellStep.
15 16 17 18 19 |
# File 'lib/rosett_ai/workflow/steps/shell_step.rb', line 15 def initialize(definition) @definition = definition @command = definition.fetch('command') validate! end |
Instance Method Details
#describe ⇒ String
Returns step description for dry-run.
22 23 24 |
# File 'lib/rosett_ai/workflow/steps/shell_step.rb', line 22 def describe "[shell] #{@definition['name']} — #{@command.join(' ')}" end |
#execute ⇒ Hash
Executes the shell command.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rosett_ai/workflow/steps/shell_step.rb', line 29 def execute start = Process.clock_gettime(Process::CLOCK_MONOTONIC) success = system(*@command) elapsed = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).round(1) if success { status: 'pass', message: "Completed: #{@command.join(' ')}", duration_ms: elapsed } else { status: 'fail', message: "Failed: #{@command.join(' ')} (exit #{$CHILD_STATUS&.exitstatus})", duration_ms: elapsed } end end |