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, suspended_action: nil)
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 9 def initialize(*_args, suspended_action: nil) @suspended_action = suspended_action @id = SecureRandom.uuid initialize_continuous_outputs end
Public Instance Methods
close()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 37 def close # if cleanup is needed end
dispatch_exception(context, exception)
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 67 def dispatch_exception(context, exception) @continuous_output.add_exception(context, exception) end
generate_updates()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 71 def generate_updates return {} if @continuous_output.empty? && @exit_status.nil? new_data = @continuous_output @continuous_output = ForemanTasksCore::ContinuousOutput.new { @suspended_action => Runner::Update.new(new_data, @exit_status) } end
initialize_continuous_outputs()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 78 def initialize_continuous_outputs @continuous_output = ::ForemanTasksCore::ContinuousOutput.new end
kill()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 33 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 15 def logger @logger ||= Logger.new(STDERR) end
publish_data(data, type)
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 52 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 56 def publish_exception(context, exception, fatal = true) logger.error("#{context} - #{exception.class} #{exception.message}:\n" + \ exception.backtrace.join("\n")) dispatch_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 63 def publish_exit_status(status) @exit_status = status end
refresh()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 29 def refresh raise NotImplementedError end
run_refresh()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 19 def run_refresh logger.debug('refreshing runner') refresh generate_updates end
start()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 25 def start raise NotImplementedError end
timeout()
click to toggle source
# File lib/foreman_tasks_core/runner/base.rb, line 41 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 47 def timeout_interval # A number of seconds after which the runner should receive a #timeout # or nil for no timeout end