Class: Actions::ForemanTemplateTasks::TemplateAction
- Inherits:
-
Base
- Object
- Base
- Actions::ForemanTemplateTasks::TemplateAction
show all
- Includes:
- RecurringAction
- Defined in:
- app/lib/actions/foreman_template_tasks/template_action.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.cleanup_after ⇒ Object
91
92
93
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 91
def self.cleanup_after
'1d'
end
|
Instance Method Details
#_plan(context: nil, **task_params) ⇒ Object
23
24
25
26
27
28
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 23
def _plan(context: nil, **task_params)
input.update context: context
input.update task_params: task_params
plan_self
end
|
#delay(delay_options, context: nil, **task_params) ⇒ Object
10
11
12
13
14
15
16
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 10
def delay(delay_options, context: nil, **task_params)
task_params = task_params.compact
input.update context: context
input.update task_params: task_params
super delay_options, { context: context, task_params: task_params }
end
|
#humanized_action ⇒ Object
64
65
66
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 64
def humanized_action
raise NotImplementedError
end
|
#humanized_name ⇒ Object
68
69
70
71
72
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 68
def humanized_name
format N_('%<action>s Foreman Templates%<context>s'),
action: humanized_action,
context: input[:context] ? " (#{input[:context]})" : ''
end
|
#humanized_output ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 30
def humanized_output
return unless output[:results]
changes = output[:results]
.select { |r| (r[:imported] || r[:exported]) && r[:changed] }
exceptions = output[:results]
.reject { |r| r[:exception].nil? }
.group_by { |r| [r[:type], r[:additional_errors] || r[:exception]] }
.map do |k, v|
"#{v.size} templates#{k.first.nil? ? '' : " of type #{k.first}"} skipped because: #{k.last}"
end
out = "#{humanized_action} finished, "
out += if changes.any?
"#{changes.count} templates changed"
else
location = self.class == TemplateImportAction ? 'local' : 'remote'
"no changes to #{location} templates"
end
out += if exceptions.any?
", #{output[:results].reject { |r| r[:exception].nil? }.count} templates skipped;\n- " + exceptions.join("\n- ")
else
'.'
end
if changes.any?
out += "\n\nTemplates changed:\n- " + changes.map { |ch| "#{ch[:type].camel_case} | #{ch[:name]}" }.join("\n- ")
end
out
end
|
#plan(args = {}) ⇒ Object
Rails passes hashes with keys as string by default
19
20
21
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 19
def plan(args = {})
_plan(args.deep_symbolize_keys)
end
|
#rescue_strategy ⇒ Object
87
88
89
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 87
def rescue_strategy
Dynflow::Action::Rescue::Skip
end
|
#task_output ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 74
def task_output
(output[:results] || []).map do |r|
{
name: r[:name],
type: r[:type],
changed: r[:changed],
imported: r[:imported],
exported: r[:exported],
error: r[:additional_errors] || r[:exception]
}.compact
end
end
|