Class: Katello::PulpTaskStatus
Constant Summary
collapse
- WAIT_TIMES =
[0.5, 1, 2, 4, 8, 16]
- WAIT_TIME_STEP =
5
Util::TaskStatus::TYPES
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from TaskStatus
#as_json, #canceled?, #description, #error?, #finished?, #generate_description, #human_readable_message, #humanize_parameters, #humanize_type, #initialize, make, #merge_pulp_task!, #message, #overall_status, #pending?, #pending_message, #refresh_pulp, #result_description, #rmi_error_description, #system_filter_clause
Methods inherited from Model
#destroy!
Class Method Details
.any_task_running(async_tasks) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/models/katello/pulp_task_status.rb', line 88
def self.any_task_running(async_tasks)
async_tasks.each do |t|
t.refresh
sleep 0.5 if !t.finished?
return true
elsif t.error?
fail t.as_json
end
end
return false
end
|
.dump_state(pulp_status, task_status) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/models/katello/pulp_task_status.rb', line 62
def self.dump_state(pulp_status, task_status)
if !pulp_status.key?(:state) && pulp_status[:result] == "success"
pulp_status[:state] = Status::FINISHED.to_s
end
task_status.attributes = {
:uuid => pulp_status[:task_id],
:state => pulp_status[:state] || pulp_status[:result],
:start_time => pulp_status[:start_time] || pulp_status[:start_time],
:finish_time => pulp_status[:finish_time],
:progress => pulp_status,
:result => pulp_status[:result].nil? ? {:errors => [pulp_status[:exception], pulp_status[:traceback]]} : pulp_status[:result]
}
task_status.save! unless task_status.new_record?
task_status
end
|
.poll_wait_time(attempts) ⇒ Object
.refresh(task_status) ⇒ Object
80
81
82
83
84
85
86
|
# File 'app/models/katello/pulp_task_status.rb', line 80
def self.refresh(task_status)
pulp_task = Katello.pulp_server.resources.task.poll(task_status.uuid)
self.dump_state(pulp_task, task_status)
task_status.after_refresh
task_status
end
|
.using_pulp_task(pulp_status) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/models/katello/pulp_task_status.rb', line 49
def self.using_pulp_task(pulp_status)
if pulp_status.is_a? TaskStatus
pulp_status
else
task_id = pulp_status[:task_id] || pulp_status[:spawned_tasks].first[:task_id]
pulp_status = Katello.pulp_server.resources.task.poll(task_id)
task_status = TaskStatus.find_by(:uuid => task_id)
task_status = self.new { |t| yield t if block_given? } if task_status.nil?
PulpTaskStatus.dump_state(pulp_status, task_status)
end
end
|
.wait_for_tasks(async_tasks) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/models/katello/pulp_task_status.rb', line 24
def self.wait_for_tasks(async_tasks)
async_tasks = async_tasks.collect do |t|
unless t.nil?
PulpTaskStatus.using_pulp_task(t)
end
end
timeout_count = 0
attempts = 0
loop do
begin
break unless any_task_running(async_tasks)
timeout_count = 0
attempts += 1
rescue RestClient::RequestTimeout => e
timeout_count += 1
Rails.logger.error "Timeout in pulp occurred: #{timeout_count}"
raise e if timeout_count >= 10 sleep 50 end
sleep poll_wait_time(attempts)
end
async_tasks
end
|
Instance Method Details
#affected_units ⇒ Object
16
17
18
|
# File 'app/models/katello/pulp_task_status.rb', line 16
def affected_units
self.result['num_changes']
end
|
#after_refresh ⇒ Object
12
13
14
|
# File 'app/models/katello/pulp_task_status.rb', line 12
def after_refresh
end
|
#error ⇒ Object
20
21
22
|
# File 'app/models/katello/pulp_task_status.rb', line 20
def error
self.result[:errors][0] if self.error? && self.result[:errors]
end
|
#refresh ⇒ Object
8
9
10
|
# File 'app/models/katello/pulp_task_status.rb', line 8
def refresh
PulpTaskStatus.refresh(self)
end
|