Class: Runcible::Resources::TaskGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/runcible/resources/task_group.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_group.rb', line 9

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

.summary_path(id) ⇒ Object



13
14
15
# File 'lib/runcible/resources/task_group.rb', line 13

def self.summary_path(id)
  "task_groups/#{id}/state_summary/"
end

Instance Method Details

#cancel(id) ⇒ RestClient::Response

cancel a task group

Parameters:

  • id (String)

    the id of the task

Returns:

  • (RestClient::Response)


39
40
41
# File 'lib/runcible/resources/task_group.rb', line 39

def cancel(id)
  call(:delete, path(id))
end

#completed?(summary_report) ⇒ Boolean

checks if all tasks in the summary report have completed

Parameters:

  • the (Hash)

    summary report obtained from summary(id) call

Returns:

  • (Boolean)

    true if tasks in the summary report have completed



28
29
30
31
32
33
34
# File 'lib/runcible/resources/task_group.rb', line 28

def completed?(summary_report)
  sum = 0
  ["finished", "canceled", "skipped", "suspended", "error"].each do |state|
    sum += summary_report[state] if summary_report[state]
  end
  sum == summary_report["total"]
end

#summary(id) ⇒ RestClient::Response

summary for the status of a task

Parameters:

  • id (String)

    the id of the task

Returns:

  • (RestClient::Response)


21
22
23
# File 'lib/runcible/resources/task_group.rb', line 21

def summary(id)
  call(:get, self.class.summary_path(id))
end