class ForemanMaintain::Runner::Execution

Class representing an execution of a single step in scenario

Attributes

ended_at[R]

Information about timings, collected automatically

output[RW]

Output of the execution, to be filled by execution step

reporter[R]
started_at[R]

Information about timings, collected automatically

status[RW]

One of :pending, :running, :success, :fail, :skipped

step[R]

Step performed as part of the execution

Public Class Methods

new(step, reporter) click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 23
def initialize(step, reporter)
  @step = step
  @reporter = reporter
  @status = :pending
  @output = ''
end

Public Instance Methods

fail?() click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 38
def fail?
  @status == :fail
end
name() click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 30
def name
  @step.description
end
run() click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 46
def run
  @status = :running
  @reporter.before_execution_starts(self)
  with_metadata_calculation do
    capture_errors do
      step.__run__(self)
    end
  end
  # change the state only when not modified
  @status = :success if @status == :running
ensure
  @reporter.after_execution_finishes(self)
end
success?() click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 34
def success?
  @status == :success
end
update(line) click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 60
def update(line)
  @reporter.on_execution_update(self, line)
end
warning?() click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 42
def warning?
  @status == :warning
end

Private Instance Methods

capture_errors() { || ... } click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 73
def capture_errors
  yield
rescue => e
  @status = :fail
  @output << e.message
  logger.error(e)
end
with_metadata_calculation() { || ... } click to toggle source
# File lib/foreman_maintain/runner/execution.rb, line 66
def with_metadata_calculation
  @started_at = Time.now
  yield
ensure
  @ended_at = Time.now
end