Class: JobInvocation
Constant Summary
collapse
- FLATTENED_ERRORS_MAPPING =
{
:pattern_template_invocations => lambda do |template_invocation|
_('template') + " #{template_invocation.template.name}"
end
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#flattened_errors, #flattened_validation_exception
Instance Attribute Details
Returns the value of attribute description_format.
61
62
63
|
# File 'app/models/job_invocation.rb', line 61
def description_format
@description_format
end
|
#start_at=(value) ⇒ Object
Sets the attribute start_at
62
63
64
|
# File 'app/models/job_invocation.rb', line 62
def start_at=(value)
@start_at = value
end
|
#start_before ⇒ Object
Returns the value of attribute start_before.
61
62
63
|
# File 'app/models/job_invocation.rb', line 61
def start_before
@start_before
end
|
Class Method Details
.search_by_recurring_logic(key, operator, value) ⇒ Object
72
73
74
75
76
77
78
|
# File 'app/models/job_invocation.rb', line 72
def self.search_by_recurring_logic(key, operator, value)
reucurring = value == 'true'
reucurring = !reucurring if operator == '<>'
not_operator = reucurring ? 'NOT' : ''
{ :conditions => sanitize_sql_for_conditions(["foreman_tasks_recurring_logics.id IS #{not_operator} NULL"]), :joins => :recurring_logic }
end
|
.search_by_status(key, operator, value) ⇒ Object
66
67
68
69
70
|
# File 'app/models/job_invocation.rb', line 66
def self.search_by_status(key, operator, value)
conditions = HostStatus::ExecutionStatus::ExecutionTaskStatusMapper.sql_conditions_for(value)
conditions[0] = "NOT (#{conditions[0]})" if operator == '<>'
{ :conditions => sanitize_sql_for_conditions(conditions), :include => :task }
end
|
Instance Method Details
#available_providers(host) ⇒ Object
TODO: determine from the host and job_invocation details
#deep_clone ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'app/models/job_invocation.rb', line 97
def deep_clone
JobInvocationComposer.from_job_invocation(self).job_invocation.tap do |invocation|
invocation.task_group = JobInvocationTaskGroup.new
invocation.triggering = self.triggering
invocation.description_format = self.description_format
invocation.description = self.description
invocation.pattern_template_invocations = self.pattern_template_invocations.map(&:deep_clone)
end
end
|
#deep_clone! ⇒ Object
107
108
109
|
# File 'app/models/job_invocation.rb', line 107
def deep_clone!
deep_clone.tap(&:save!)
end
|
#failed_host_ids ⇒ Object
119
120
121
|
# File 'app/models/job_invocation.rb', line 119
def failed_host_ids
failed_template_invocations.map(&:host_id)
end
|
#failed_hosts ⇒ Object
123
124
125
|
# File 'app/models/job_invocation.rb', line 123
def failed_hosts
failed_template_invocations.includes(:host).map(&:host)
end
|
#failed_template_invocation_tasks ⇒ Object
115
116
117
|
# File 'app/models/job_invocation.rb', line 115
def failed_template_invocation_tasks
template_invocation_tasks.where(:result => [ 'error', 'warning' ])
end
|
#generate_description ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/models/job_invocation.rb', line 160
def generate_description
key_re = /%\{([^\}]+)\}/
template_invocation = pattern_template_invocations.first
input_names = template_invocation.template.template_inputs_with_foreign(&:name)
hash_base = Hash.new { |hash, key| hash[key] = "%{#{key}}" }
input_hash = hash_base.merge Hash[input_names.zip(template_invocation.input_values.map(&:value))]
input_hash.update(:job_category => job_category)
input_hash.update(:template_name => template_invocation.template.name)
description_format.scan(key_re) { |key| input_hash[key.first] }
self.description = description_format
input_hash.each do |k, v|
self.description.gsub!(Regexp.new("%\{#{k}\}"), v || '')
end
self.description = self.description[0..(JobInvocation.columns_hash['description'].limit - 1)]
end
|
#output(host) ⇒ Object
155
156
157
158
|
# File 'app/models/job_invocation.rb', line 155
def output(host)
return unless (task = sub_task_for_host(host)) && task.main_action && task.main_action.live_output.any?
task.main_action.live_output.first['output']
end
|
#pattern_template_invocation_for_host(host) ⇒ Object
135
136
137
138
139
140
141
142
143
144
|
# File 'app/models/job_invocation.rb', line 135
def pattern_template_invocation_for_host(host)
providers = available_providers(host)
providers.each do |provider|
pattern_template_invocations.each do |template_invocation|
if template_invocation.template.provider_type == provider
return template_invocation
end
end
end
end
|
#progress ⇒ Object
returns progress in percents
89
90
91
|
# File 'app/models/job_invocation.rb', line 89
def progress
queued? ? 0 : (task.progress * 100).to_i
end
|
#queued? ⇒ Boolean
93
94
95
|
# File 'app/models/job_invocation.rb', line 93
def queued?
status == HostStatus::ExecutionStatus::QUEUED
end
|
#status ⇒ Object
80
81
82
|
# File 'app/models/job_invocation.rb', line 80
def status
HostStatus::ExecutionStatus::ExecutionTaskStatusMapper.new(task).status
end
|
#status_label ⇒ Object
84
85
86
|
# File 'app/models/job_invocation.rb', line 84
def status_label
HostStatus::ExecutionStatus::ExecutionTaskStatusMapper.new(task).status_label
end
|
#sub_task_for_host(host) ⇒ Object
151
152
153
|
# File 'app/models/job_invocation.rb', line 151
def sub_task_for_host(host)
template_invocations.find_by(:host => host.id).try(:run_host_job_task)
end
|
111
112
113
|
# File 'app/models/job_invocation.rb', line 111
def to_action_input
{ :id => id, :name => job_category, :description => description }
end
|
#total_hosts_count ⇒ Object
127
128
129
130
131
132
133
|
# File 'app/models/job_invocation.rb', line 127
def total_hosts_count
if targeting.resolved?
targeting.hosts.count
else
_('N/A')
end
end
|