Class: ForemanTasksCore::Runner::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_tasks_core/runner/base.rb

Overview

Runner is an object that is able to initiate some action and provide update data on refresh call.

Direct Known Subclasses

CommandRunner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/foreman_tasks_core/runner/base.rb', line 9

def initialize(*_args)
  @id = SecureRandom.uuid
  @continuous_output = ::ForemanTasksCore::ContinuousOutput.new
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/foreman_tasks_core/runner/base.rb', line 6

def id
  @id
end

#loggerObject



14
15
16
# File 'lib/foreman_tasks_core/runner/base.rb', line 14

def logger
  @logger ||= Logger.new(STDERR)
end

Instance Method Details

#closeObject



40
41
42
# File 'lib/foreman_tasks_core/runner/base.rb', line 40

def close
  # if cleanup is needed
end

#killObject



36
37
38
# File 'lib/foreman_tasks_core/runner/base.rb', line 36

def kill
  # Override when you can kill the runner in the middle
end

#publish_data(data, type) ⇒ Object



55
56
57
# File 'lib/foreman_tasks_core/runner/base.rb', line 55

def publish_data(data, type)
  @continuous_output.add_output(data, type)
end

#publish_exception(context, exception, fatal = true) ⇒ Object



59
60
61
62
63
64
# File 'lib/foreman_tasks_core/runner/base.rb', line 59

def publish_exception(context, exception, fatal = true)
  logger.error("#{context} - #{exception.class} #{exception.message}:\n" + \
               exception.backtrace.join("\n"))
  @continuous_output.add_exception(context, exception)
  publish_exit_status('EXCEPTION') if fatal
end

#publish_exit_status(status) ⇒ Object



66
67
68
# File 'lib/foreman_tasks_core/runner/base.rb', line 66

def publish_exit_status(status)
  @exit_status = status
end

#refreshObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/foreman_tasks_core/runner/base.rb', line 32

def refresh
  raise NotImplementedError
end

#run_refreshObject



18
19
20
21
22
23
24
25
26
# File 'lib/foreman_tasks_core/runner/base.rb', line 18

def run_refresh
  logger.debug('refreshing runner')
  refresh
  new_data = @continuous_output
  @continuous_output = ForemanTasksCore::ContinuousOutput.new
  if !new_data.empty? || @exit_status
    return Runner::Update.new(new_data, @exit_status)
  end
end

#startObject

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/foreman_tasks_core/runner/base.rb', line 28

def start
  raise NotImplementedError
end

#timeoutObject



44
45
46
47
48
# File 'lib/foreman_tasks_core/runner/base.rb', line 44

def timeout
  # Override when timeouts and regular kills should be handled differently
  publish_data('Timeout for execution passed, trying to stop the job', 'debug')
  kill
end

#timeout_intervalObject



50
51
52
53
# File 'lib/foreman_tasks_core/runner/base.rb', line 50

def timeout_interval
  # A number of seconds after which the runner should receive a #timeout
  #   or nil for no timeout
end