class DTK::Client::Operation::Service::TaskStatus

Constants

DEFAULT_MODE

Public Class Methods

execute(args = Args.new) click to toggle source
# File lib/client/operation/service/task_status.rb, line 30
def self.execute(args = Args.new)
  wrap_operation(args) do |args|
    service_instance = args.required(:service_instance)
    task_status_mode = args[:mode]
    info             = nil

    task_status_mode ||=  DEFAULT_MODE 
    task_status_with_mode(task_status_mode.to_sym, service_instance)
  end
end
new(mode, service_instance) click to toggle source
# File lib/client/operation/service/task_status.rb, line 25
def initialize(mode, service_instance)
  @mode             = mode
  @service_instance = service_instance
end

Private Class Methods

query_string_hash(opts = {}) click to toggle source
# File lib/client/operation/service/task_status.rb, line 76
def self.query_string_hash(opts = {})
  QueryStringHash.new( 
    :form?                  => opts[:form],
    :wait_for?              => opts[:wait_for],
    :summarize_node_groups? => opts[:summarize],
    :task_id?               => opts[:task_id]
  )
end
rest_call(service_instance, opts = {}) click to toggle source
# File lib/client/operation/service/task_status.rb, line 72
def self.rest_call(service_instance, opts = {})
  rest_get("#{BaseRoute}/#{service_instance}/task_status", query_string_hash(opts))
end
task_status_with_mode(mode, service_instance, opts = {}) click to toggle source
# File lib/client/operation/service/task_status.rb, line 49
def self.task_status_with_mode(mode, service_instance, opts = {})
  Dir.glob("*", File::FNM_DOTMATCH).each do |f|
    if match = /^(.task_id_)(\d*)/.match(f)
      opts[:task_id] = match[2] if match[2]
      break
    end
  end
  case mode
  when :refresh
    RefreshMode.new(mode, service_instance).task_status(opts)
  when :snapshot 
    SnapshotMode.new(mode, service_instance).task_status(opts)
  when :stream
    begin
    StreamMode.new(mode, service_instance).get_and_render(opts)
    rescue Interrupt => e
      puts "Exiting ..."
    end
  else
    raise Error::Usage.new("Illegal mode '#{mode}'; legal modes are: #{LEGAL_MODES.join(', ')}")
  end
end

Public Instance Methods

rest_call(opts = {}) click to toggle source
# File lib/client/operation/service/task_status.rb, line 41
def rest_call(opts = {})
  self.class.rest_call(@service_instance, opts)
end

Private Instance Methods

add_info_if_debug_mode!(response) click to toggle source
# File lib/client/operation/service/task_status.rb, line 85
def add_info_if_debug_mode!(response)
  debug_info_rows = debug_mode_rows(response).select { |row| (row['info'] || {})['message'] }
  if debug_info_rows.size > 0
    info_message = debug_info_rows.last['info']['message']
    response.set_render_as_table!(nil, info_message)
  else
    response.set_render_as_table!
  end
end
debug_mode?(response) click to toggle source
# File lib/client/operation/service/task_status.rb, line 95
def debug_mode?(response)
  debug_mode_rows(response).size > 0
end
debug_mode_rows(response) click to toggle source
# File lib/client/operation/service/task_status.rb, line 99
def debug_mode_rows(response)
  response['data'].select { |data_row| data_row['status'] == 'debugging' }
end