class ForemanTasksCore::Runner::Base

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

Attributes

id[R]
logger[W]

Public Class Methods

new(*_args) click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 9
def initialize(*_args)
  @id = SecureRandom.uuid
  @continuous_output = ::ForemanTasksCore::ContinuousOutput.new
end

Public Instance Methods

close() click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 40
def close
  # if cleanup is needed
end
kill() click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 36
def kill
  # Override when you can kill the runner in the middle
end
logger() click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 14
def logger
  @logger ||= Logger.new(STDERR)
end
publish_data(data, type) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 66
def publish_exit_status(status)
  @exit_status = status
end
refresh() click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 32
def refresh
  raise NotImplementedError
end
run_refresh() click to toggle source
# 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
start() click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 28
def start
  raise NotImplementedError
end
timeout() click to toggle source
# 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_interval() click to toggle source
# 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