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
94
95
96
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 94
def self.cleanup_after
'1d'
end
|
Instance Method Details
#_plan(context: nil, **task_params) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 23
def _plan(context: nil, **task_params)
task_params = task_params[:task_params] if task_params.key? :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
67
68
69
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 67
def humanized_action
raise NotImplementedError
end
|
#humanized_name ⇒ Object
71
72
73
74
75
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 71
def humanized_name
format N_('%<action>s Foreman Templates%<context>s'),
action: humanized_action,
context: input[:context] ? " (#{input[:context]})" : ''
end
|
#humanized_output ⇒ Object
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
63
64
65
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 33
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].camelcase} | #{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
90
91
92
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 90
def rescue_strategy
Dynflow::Action::Rescue::Skip
end
|
#task_output ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/lib/actions/foreman_template_tasks/template_action.rb', line 77
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
|