class ForemanTasks::ContinuousOutput

Attributes

raw_outputs[RW]

Public Class Methods

format_output(message, type = 'debug', timestamp = Time.now.getlocal) click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 44
def self.format_output(message, type = 'debug', timestamp = Time.now.getlocal)
  { 'output_type' => type,
    'output' => message,
    'timestamp' => timestamp.to_f }
end
new(raw_outputs = []) click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 5
def initialize(raw_outputs = [])
  @raw_outputs = []
  raw_outputs.each { |raw_output| add_raw_output(raw_output) }
end

Public Instance Methods

add_exception(context, exception, timestamp = Time.now.getlocal) click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 36
def add_exception(context, exception, timestamp = Time.now.getlocal)
  add_output(context + ": #{exception.class} - #{exception.message}", 'debug', timestamp)
end
add_output(*args) click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 40
def add_output(*args)
  add_raw_output(self.class.format_output(*args))
end
add_raw_output(raw_output) click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 10
def add_raw_output(raw_output)
  missing_args = %w[output_type output timestamp] - raw_output.keys
  unless missing_args.empty?
    raise ArgumentError, "Missing args for raw output: #{missing_args.inspect}"
  end
  @raw_outputs << raw_output
end
empty?() click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 18
def empty?
  @raw_outputs.empty?
end
humanize() click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 31
def humanize
  sort!
  raw_outputs.map { |output| output['output'] }.join("\n")
end
last_timestamp() click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 22
def last_timestamp
  return if @raw_outputs.empty?
  @raw_outputs.last.fetch('timestamp')
end
sort!() click to toggle source
# File lib/foreman_tasks/continuous_output.rb, line 27
def sort!
  @raw_outputs.sort_by! { |record| record['timestamp'].to_f }
end