class DTK::Client::Task

Constants

TASK_STATUS_MAX_TIME
TASK_STATUS_POLLING_INTERVAL

Public Class Methods

whoami() click to toggle source
# File lib/commands/thor/task.rb, line 21
def self.whoami()
  return :task, "task/list", nil
end

Public Instance Methods

commit_changes(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 53
def commit_changes(context_params)
  scope = context_params.retrieve_arguments([:option_1],method_argument_names)
  post_hash_body = Hash.new
  post_hash_body.merge!(:scope => scope) if scope
  post rest_url("task/create_task_from_pending_changes"),post_hash_body
end
commit_changes_and_execute(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 67
def commit_changes_and_execute(context_params)
  response = commit_changes(context_params)
  if response.ok?
    execute(response.data(:task_id))
  else
    response
  end
end
converge_node(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 82
def converge_node(context_params)
  node_id = context_params.retrieve_arguments([:option_1!],method_argument_names)

  scope = node_id && {:node_id => node_id} 
  response = post(rest_url("task/create_converge_state_changes"),scope)
  return response unless response.ok?
  response = commit_changes_and_execute(scope)
  while not task_complete(response) do
    response = status()
    sleep(TASK_STATUS_POLLING_INTERVAL)
  end
  response
end
converge_nodes() click to toggle source
# File lib/commands/thor/task.rb, line 97
def converge_nodes()
  converge_node(nil)
end
execute(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 61
def execute(context_params)
  task_id = context_params.retrieve_arguments([:task_id!],method_argument_names)
  post rest_url("task/execute"), :task_id => task_id
end
list(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 28
def list(context_params)

  #TODO: just hard coded params now
  search_hash = SearchHash.new()
  search_hash.cols = [:commit_message,:status,:id,:created_at,:started_at,:ended_at]
  search_hash.filter = [:eq, ":task_id", nil] #just top level tasks
  search_hash.set_order_by!(:created_at,"DESC")
  response = post rest_url("task/list"), search_hash.post_body_hash()
  
  response.render_table(:task) unless options.list?
  return response
end
simple_run(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 77
def simple_run(context_params)
  commit_changes_and_execute(context_params)
end
status(context_params) click to toggle source
# File lib/commands/thor/task.rb, line 43
def status(context_params)
  task_id = context_params.retrieve_arguments([:task_id],method_argument_names)
  detail_level = options["detail-level"]
  post_hash_body = Hash.new
  post_hash_body[:detail_level] = detail_level if detail_level
  post_hash_body[:task_id] = task_id if task_id
  post rest_url("task/status"),post_hash_body
end

Private Instance Methods

task_complete(response) click to toggle source
# File lib/commands/thor/task.rb, line 108
def task_complete(response)
  return true unless response.ok?
  @@count += 1
  return true if (@@count * TASK_STATUS_POLLING_INTERVAL) > TASK_STATUS_MAX_TIME
  %w{succeeded failed}.include?(response.data(:status))
end