Class: Runcible::Resources::Task

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

Overview

Instance Attribute Summary

Attributes inherited from Base

#logs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_http_auth_header, #add_oauth_header, #call, #combine_get_params, #config, #exception_to_log, #format_payload_json, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #log_info, #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



9
10
11
# File 'lib/runcible/resources/task.rb', line 9

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)


25
26
27
28
29
# File 'lib/runcible/resources/task.rb', line 25

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)


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

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)


17
18
19
# File 'lib/runcible/resources/task.rb', line 17

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



44
45
46
# File 'lib/runcible/resources/task.rb', line 44

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