Project

General

Profile

Download (1.2 KB) Statistics
| Branch: | Tag: | Revision:

runcible / lib / runcible / resources / task_group.rb @ 27b106f4

1
module Runcible
2
  module Resources
3
    # @see https://docs.pulpproject.org/dev-guide/integration/rest-api/dispatch/index.html
4
    class TaskGroup < Runcible::Base
5
      # Generates the API path for Tasks
6
      #
7
      # @param  [String]  id  the id of the task
8
      # @return [String]      the task path, may contain the id if passed
9
      def self.path(id = nil)
10
        id.nil? ? 'task_groups/' : "task_groups/#{id}/"
11
      end
12

    
13
      def self.summary_path(id)
14
        "task_groups/#{id}/state_summary/"
15
      end
16

    
17
      # summary for the status of a task
18
      #
19
      # @param  [String]              id  the id of the task
20
      # @return [RestClient::Response]
21
      def summary(id)
22
        call(:get, self.class.summary_path(id))
23
      end
24

    
25
      # checks if all tasks in the summary report have completed
26
      # @param [Hash] the summary report obtained from summary(id) call
27
      # @return true if tasks in the summary report have completed
28
      def completed?(summary_report)
29
        sum = 0
30
        ["finished", "canceled", "skipped", "suspended", "error"].each do |state|
31
          sum += summary_report[state] if summary_report[state]
32
        end
33
        sum == summary_report["total"]
34
      end
35
    end
36
  end
37
end