Class: Katello::Pulp3::TaskGroup
- Inherits:
-
Object
- Object
- Katello::Pulp3::TaskGroup
- Defined in:
- app/services/katello/pulp3/task_group.rb
Constant Summary collapse
- WAITING =
'waiting'.freeze
- SKIPPED =
'skipped'.freeze
- RUNNING =
'running'.freeze
- COMPLETED =
'completed'.freeze
- CANCELLED =
'canceled'.freeze
- FAILED =
'failed'.freeze
- IN_PROGRESS_STATES =
[WAITING, RUNNING].freeze
Instance Attribute Summary collapse
-
#href ⇒ Object
Returns the value of attribute href.
-
#pulp_data ⇒ Object
readonly
Returns the value of attribute pulp_data.
Class Method Summary collapse
-
.new_from_href(smart_proxy, href) ⇒ Object
A call report Looks like: “task”:“/pulp/api/v3/tasks/5/” { “pulp_href”:“/pulp/api/v3/task-groups/d9841aaa-8a47-4e31-9018-10e4430766bf/”, “description”:“Migration Sub-tasks”, “waiting”:0, “skipped”:0, “running”:0, “completed”:0, “canceled”:0, “failed”:1 }.
Instance Method Summary collapse
- #cancel ⇒ Object
- #clear_task_group_data ⇒ Object
- #core_api ⇒ Object
- #done? ⇒ Boolean
- #error ⇒ Object
- #group_progress_reports ⇒ Object
-
#initialize(smart_proxy, data) ⇒ TaskGroup
constructor
A new instance of TaskGroup.
- #poll ⇒ Object
- #query_task_group_errors(task_group_data) ⇒ Object
- #started? ⇒ Boolean
- #task_group_data ⇒ Object
- #tasks_api ⇒ Object
- #tasks_groups_api ⇒ Object
Constructor Details
#initialize(smart_proxy, data) ⇒ TaskGroup
Returns a new instance of TaskGroup.
38 39 40 41 42 43 |
# File 'app/services/katello/pulp3/task_group.rb', line 38 def initialize(smart_proxy, data) @smart_proxy = smart_proxy @pulp_data = data.with_indifferent_access @href = @pulp_data['pulp_href'] Rails.logger.error("Got empty pulp_href on #{@pulp_data}") if @href.nil? end |
Instance Attribute Details
#href ⇒ Object
Returns the value of attribute href.
17 18 19 |
# File 'app/services/katello/pulp3/task_group.rb', line 17 def href @href end |
#pulp_data ⇒ Object (readonly)
Returns the value of attribute pulp_data.
18 19 20 |
# File 'app/services/katello/pulp3/task_group.rb', line 18 def pulp_data @pulp_data end |
Class Method Details
.new_from_href(smart_proxy, href) ⇒ Object
A call report Looks like: “task”:“/pulp/api/v3/tasks/5/” { “pulp_href”:“/pulp/api/v3/task-groups/d9841aaa-8a47-4e31-9018-10e4430766bf/”,
"description":"Migration Sub-tasks",
"waiting":0,
"skipped":0,
"running":0,
"completed":0,
"canceled":0,
"failed":1
}
32 33 34 35 36 |
# File 'app/services/katello/pulp3/task_group.rb', line 32 def self.new_from_href(smart_proxy, href) group = self.new(smart_proxy, {'pulp_href' => href}) group.clear_task_group_data group end |
Instance Method Details
#cancel ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'app/services/katello/pulp3/task_group.rb', line 104 def cancel tasks_api = core_api.tasks_api tasks_response = core_api.class.fetch_from_list do |page_opts| tasks_api.list(page_opts.merge(task_group: task_group_data['pulp_href'], state__in: [RUNNING, WAITING])) end tasks_response.collect do |result| ::Katello::Pulp3::Api::Core.new(@smart_proxy).cancel_task(result.pulp_href) end end |
#clear_task_group_data ⇒ Object
70 71 72 |
# File 'app/services/katello/pulp3/task_group.rb', line 70 def clear_task_group_data @pulp_data = nil end |
#core_api ⇒ Object
100 101 102 |
# File 'app/services/katello/pulp3/task_group.rb', line 100 def core_api ::Katello::Pulp3::Api::Core.new(@smart_proxy) end |
#done? ⇒ Boolean
57 58 59 |
# File 'app/services/katello/pulp3/task_group.rb', line 57 def done? task_group_data['all_tasks_dispatched'] == true && IN_PROGRESS_STATES.all? { |state| task_group_data[state] == 0 } end |
#error ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/services/katello/pulp3/task_group.rb', line 78 def error return if task_group_data[WAITING] > 0 || task_group_data[RUNNING] > 0 if task_group_data[FAILED] > 0 = query_task_group_errors(task_group_data) return "#{task_group_data[FAILED]} subtask(s) failed for task group #{@href}.\nErrors:\n #{.join("\n")}" elsif task_group_data[CANCELLED] > 0 "#{task_group_data[CANCELLED]} subtask(s) cancelled for task group #{@href}." end end |
#group_progress_reports ⇒ Object
61 62 63 |
# File 'app/services/katello/pulp3/task_group.rb', line 61 def group_progress_reports task_group_data['group_progress_reports'] end |
#poll ⇒ Object
65 66 67 68 |
# File 'app/services/katello/pulp3/task_group.rb', line 65 def poll clear_task_group_data task_group_data end |
#query_task_group_errors(task_group_data) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/services/katello/pulp3/task_group.rb', line 88 def query_task_group_errors(task_group_data) = [] tasks_api = core_api.tasks_api tasks_response = core_api.class.fetch_from_list do |page_opts| tasks_api.list(page_opts.merge(task_group: task_group_data['pulp_href'], state__in: [FAILED])) end tasks_response.collect do |result| << result.error end return end |
#started? ⇒ Boolean
74 75 76 |
# File 'app/services/katello/pulp3/task_group.rb', line 74 def started? [SKIPPED, RUNNING, COMPLETED, CANCELLED, FAILED].any? { |state| task_group_data[state] } end |
#task_group_data ⇒ Object
45 46 47 |
# File 'app/services/katello/pulp3/task_group.rb', line 45 def task_group_data @pulp_data ||= tasks_groups_api.read(@href).as_json.with_indifferent_access end |