Class: Runcible::Resources::Task

Inherits:
Base
  • Object
show all
Defined in:
lib/runcible/resources/task.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_http_auth_header, #add_oauth_header, #call, #combine_get_params, #config, #format_payload_json, #generate_log_message, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #logger, #path, #process_response, #required_params

Constructor Details

This class inherits a constructor from Runcible::Base

Class Method Details

.path(id = nil) ⇒ String

Generates the API path for Tasks

Parameters:

  • id (String) (defaults to: nil)

    the id of the task

Returns:

  • (String)

    the task path, may contain the id if passed



34
35
36
# File 'lib/runcible/resources/task.rb', line 34

def self.path(id=nil)
  (id == nil) ? "tasks/" : "tasks/#{id}/" 
end

Instance Method Details

#cancel(id) ⇒ RestClient::Response

Cancels a task

Parameters:

  • id (String)

    the id of the task

Returns:

  • (RestClient::Response)


50
51
52
53
54
# File 'lib/runcible/resources/task.rb', line 50

def cancel(id)
  #cancelling a task may require cancelling some higher level
  #  task, so query the tasks _href field to make sure
  call(:delete, poll(id)['_href'])
end

#list(tags = []) ⇒ RestClient::Response

List all tasks based on a set of tags

Parameters:

  • tags (Array) (defaults to: [])

    array of tags to scope the list on

Returns:

  • (RestClient::Response)


60
61
62
# File 'lib/runcible/resources/task.rb', line 60

def list(tags=[])
  call(:get, path, :params=>{:tag=>tags})
end

#poll(id) ⇒ RestClient::Response

Polls for the status of a task

Parameters:

  • id (String)

    the id of the task

Returns:

  • (RestClient::Response)


42
43
44
# File 'lib/runcible/resources/task.rb', line 42

def poll(id)
  call(:get, path(id))
end

#poll_all(ids) ⇒ Array

Polls all tasks based on array of IDs temporary solution until bugzilla.redhat.com/show_bug.cgi?id=860089

Parameters:

  • ids (Array)

    array of ids to poll the status of

Returns:

  • (Array)

    array of RestClient::Response task poll objects



69
70
71
# File 'lib/runcible/resources/task.rb', line 69

def poll_all(ids)
  return ids.collect{|id| poll(id)}
end