Class: ForemanTasks::Task
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanTasks::Task
show all
- Extended by:
- Search
- Includes:
- Authorizable
- Defined in:
- app/models/foreman_tasks/task.rb,
app/models/foreman_tasks/task/search.rb
Defined Under Namespace
Modules: Search
Classes: DynflowTask, Jail, StatusExplicator, Summarizer, TaskCancelledException
Constant Summary
Constants included
from Search
Search::SUPPORTED_DURATION_FORMAT
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Search
search_by_duration, search_by_generic_resource, search_by_taxonomy
Class Method Details
.authorized_resource_name ⇒ Object
203
204
205
206
|
# File 'app/models/foreman_tasks/task.rb', line 203
def self.authorized_resource_name
'ForemanTasks::Task'
end
|
Instance Method Details
#action ⇒ Object
234
235
236
237
|
# File 'app/models/foreman_tasks/task.rb', line 234
def action
return to_label if super.blank?
super
end
|
#action_continuous_output ⇒ Object
252
253
254
255
256
|
# File 'app/models/foreman_tasks/task.rb', line 252
def action_continuous_output
return unless main_action.is_a?(Actions::Helpers::WithContinuousOutput)
main_action.continuous_output.sort!
main_action.continuous_output.raw_outputs
end
|
#add_missing_task_groups(groups) ⇒ Object
208
209
210
211
212
|
# File 'app/models/foreman_tasks/task.rb', line 208
def add_missing_task_groups(groups)
groups = [groups] unless groups.is_a? Array
(groups - task_groups).each { |group| task_groups << group }
save!
end
|
#build_notifications ⇒ Object
#check_permissions_after_save ⇒ Object
8
9
10
11
12
13
|
# File 'app/models/foreman_tasks/task.rb', line 8
def check_permissions_after_save
true
end
|
#cli_example ⇒ Object
137
138
139
|
# File 'app/models/foreman_tasks/task.rb', line 137
def cli_example
''
end
|
#delayed? ⇒ Boolean
returns true if the task was planned to execute in the future
165
166
167
|
# File 'app/models/foreman_tasks/task.rb', line 165
def delayed?
start_at.to_i != started_at.to_i
end
|
#execution_type ⇒ Object
111
112
113
|
# File 'app/models/foreman_tasks/task.rb', line 111
def execution_type
delayed? ? N_('Delayed') : N_('Immediate')
end
|
#get_humanized(method) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'app/models/foreman_tasks/task.rb', line 115
def get_humanized(method)
attr = case method
when :humanized_name
:action
when :humanized_input
:input
when :humanized_output
:output
end
if attr
humanized[attr]
else
_('N/A')
end
end
|
#humanized ⇒ Object
131
132
133
134
135
|
# File 'app/models/foreman_tasks/task.rb', line 131
def humanized
{ action: action,
input: '',
output: '' }
end
|
95
96
97
|
# File 'app/models/foreman_tasks/task.rb', line 95
def input
{}
end
|
#notification_recipients_ids ⇒ Object
used by Foreman notifications framework
176
177
178
|
# File 'app/models/foreman_tasks/task.rb', line 176
def notification_recipients_ids
[owner.id]
end
|
#output ⇒ Object
99
100
101
|
# File 'app/models/foreman_tasks/task.rb', line 99
def output
{}
end
|
#owner ⇒ Object
103
104
105
|
# File 'app/models/foreman_tasks/task.rb', line 103
def owner
user
end
|
#paused? ⇒ Boolean
151
152
153
|
# File 'app/models/foreman_tasks/task.rb', line 151
def paused?
state == 'paused'
end
|
#pending? ⇒ Boolean
Also known as:
pending
returns true if the task is running or waiting to be run
142
143
144
|
# File 'app/models/foreman_tasks/task.rb', line 142
def pending?
state != 'stopped'
end
|
#progress ⇒ Object
192
193
194
195
196
197
198
199
200
201
|
# File 'app/models/foreman_tasks/task.rb', line 192
def progress
case state.to_s
when 'running', 'paused'
0.5
when 'stopped'
1
else
0
end
end
|
#recurring? ⇒ Boolean
160
161
162
|
# File 'app/models/foreman_tasks/task.rb', line 160
def recurring?
!recurring_logic_task_group_ids.empty?
end
|
#resumable? ⇒ Boolean
147
148
149
|
# File 'app/models/foreman_tasks/task.rb', line 147
def resumable?
false
end
|
#scheduled? ⇒ Boolean
returns true if the task is CURRENTLY waiting to be executed in the future
156
157
158
|
# File 'app/models/foreman_tasks/task.rb', line 156
def scheduled?
state == 'scheduled'
end
|
#self_and_parents ⇒ Object
169
170
171
172
173
|
# File 'app/models/foreman_tasks/task.rb', line 169
def self_and_parents
[self].tap do |ret|
ret.concat(parent_task.self_and_parents) if parent_task
end
end
|
#sub_tasks_counts ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'app/models/foreman_tasks/task.rb', line 214
def sub_tasks_counts
result = %w[cancelled error pending success warning].inject({}) do |hash, state|
hash.update(state => 0)
end
result.update sub_tasks.group(:result).count
sum = result.values.reduce(:+)
if respond_to?(:main_action) && main_action.respond_to?(:total_count)
result[:total] = main_action.total_count
key = state == 'stopped' ? 'cancelled' : 'pending'
result[key] += result[:total] - sum
else
result[:total] = sum
end
result.symbolize_keys
end
|
#to_label ⇒ Object
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'app/models/foreman_tasks/task.rb', line 239
def to_label
parts = []
parts << get_humanized(:name)
parts << Array(get_humanized(:input)).map do |part|
if part.is_a? Array
part[1][:text]
else
part.to_s
end
end.join('; ')
parts.join(' ').strip
end
|
#username ⇒ Object
107
108
109
|
# File 'app/models/foreman_tasks/task.rb', line 107
def username
owner.try(:login)
end
|