Class: ForemanMaintain::Runner::Execution

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Concerns::Logger
Defined in:
lib/foreman_maintain/runner/execution.rb

Overview

Class representing an execution of a single step in scenario

Direct Known Subclasses

StoredExecution

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Logger

#logger

Constructor Details

#initialize(step, reporter, options = {}) ⇒ Execution

Returns a new instance of Execution.



23
24
25
26
27
28
29
30
31
32
# File 'lib/foreman_maintain/runner/execution.rb', line 23

def initialize(step, reporter, options = {})
  options.validate_options!(:whitelisted, :storage, :force)
  @step = step
  @reporter = reporter
  @status = :pending
  @output = ''
  @whitelisted = options[:whitelisted]
  @storage = options[:storage]
  @force = options[:force]
end

Instance Attribute Details

#ended_atObject (readonly)

Information about timings, collected automatically



13
14
15
# File 'lib/foreman_maintain/runner/execution.rb', line 13

def ended_at
  @ended_at
end

#outputObject

Output of the execution, to be filled by execution step



19
20
21
# File 'lib/foreman_maintain/runner/execution.rb', line 19

def output
  @output
end

#reporterObject (readonly)

Returns the value of attribute reporter.



21
22
23
# File 'lib/foreman_maintain/runner/execution.rb', line 21

def reporter
  @reporter
end

#started_atObject (readonly)

Information about timings, collected automatically



13
14
15
# File 'lib/foreman_maintain/runner/execution.rb', line 13

def started_at
  @started_at
end

#statusObject

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



16
17
18
# File 'lib/foreman_maintain/runner/execution.rb', line 16

def status
  @status
end

#stepObject (readonly)

Step performed as part of the execution



10
11
12
# File 'lib/foreman_maintain/runner/execution.rb', line 10

def step
  @step
end

Instance Method Details

#aborted?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/foreman_maintain/runner/execution.rb', line 50

def aborted?
  @status == :abort
end

#fail?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/foreman_maintain/runner/execution.rb', line 46

def fail?
  @status == :fail
end

#nameObject



34
35
36
# File 'lib/foreman_maintain/runner/execution.rb', line 34

def name
  @step.description
end

#runObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/foreman_maintain/runner/execution.rb', line 71

def run
  @reporter.before_execution_starts(self)

  if skip?
    @status = :already_run
    return
  end

  @status = whitelisted? ? :skipped : :running

   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

#skip?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/foreman_maintain/runner/execution.rb', line 58

def skip?
  !@force && step.run_once? && step.executed? && step.success?
end

#skipped?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/foreman_maintain/runner/execution.rb', line 54

def skipped?
  @status == :skipped
end

#storageObject

yaml storage to preserve key/value pairs between runs.



67
68
69
# File 'lib/foreman_maintain/runner/execution.rb', line 67

def storage
  @storage || ForemanMaintain.storage(:default)
end

#success?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/foreman_maintain/runner/execution.rb', line 42

def success?
  [:success, :already_run, :skipped].include?(@status)
end

#update(line) ⇒ Object



93
94
95
# File 'lib/foreman_maintain/runner/execution.rb', line 93

def update(line)
  @reporter.on_execution_update(self, line)
end

#warning?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/foreman_maintain/runner/execution.rb', line 62

def warning?
  @status == :warning
end

#whitelisted?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/foreman_maintain/runner/execution.rb', line 38

def whitelisted?
  @whitelisted
end