Class: Actions::Katello::AgentAction
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::AgentAction
show all
- Includes:
- Helpers::Presenter, Dynflow::Action::Timeouts
- Defined in:
- app/lib/actions/katello/agent_action.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.agent_message ⇒ Object
7
8
9
|
# File 'app/lib/actions/katello/agent_action.rb', line 7
def self.agent_message
fail NotImplementedError
end
|
Instance Method Details
#accept_timeout ⇒ Object
72
73
74
|
# File 'app/lib/actions/katello/agent_action.rb', line 72
def accept_timeout
Setting['content_action_accept_timeout']
end
|
#agent_action_type ⇒ Object
11
12
13
|
# File 'app/lib/actions/katello/agent_action.rb', line 11
def agent_action_type
nil
end
|
#dispatch_history ⇒ Object
114
115
116
|
# File 'app/lib/actions/katello/agent_action.rb', line 114
def dispatch_history
::Katello::Agent::DispatchHistory.find_by_id(input[:dispatch_history_id])
end
|
#dispatch_message(history) ⇒ Object
64
65
66
67
68
69
70
|
# File 'app/lib/actions/katello/agent_action.rb', line 64
def dispatch_message(history)
::Katello::Agent::Dispatcher.dispatch(
self.class.agent_message,
[history],
content: input[:content]
)
end
|
#fail_on_errors ⇒ Object
98
99
100
101
102
103
104
|
# File 'app/lib/actions/katello/agent_action.rb', line 98
def fail_on_errors
errors = presenter.error_messages
if errors.any?
fail errors.join("\n")
end
end
|
#finish_timeout ⇒ Object
76
77
78
|
# File 'app/lib/actions/katello/agent_action.rb', line 76
def finish_timeout
Setting['content_action_finish_timeout']
end
|
#plan(host, options) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/lib/actions/katello/agent_action.rb', line 15
def plan(host, options)
action_subject(host, :hostname => host.name, :content => options[:content])
dispatch_history_id = options.dig(:dispatch_histories, host.id.to_s) || ::Katello::Agent::Dispatcher.create_histories(
host_ids: [host.id]
).first.id
plan_self(
host_id: host.id,
dispatch_history_id: dispatch_history_id,
content: options[:content],
bulk: options[:bulk]
)
end
|
#process_timeout ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/lib/actions/katello/agent_action.rb', line 80
def process_timeout
history = dispatch_history
unless history.accepted?
fail _("Host did not respond within %s seconds. The task has been cancelled. Is katello-agent installed and goferd running on the Host?") % accept_timeout
end
unless history.finished?
finish_limit = history.accepted_at + finish_timeout
if finish_limit < DateTime.now
fail _("Host did not finish content action in %s seconds. The task has been cancelled.") % finish_timeout
end
suspend
end
end
|
#rescue_strategy ⇒ Object
110
111
112
|
# File 'app/lib/actions/katello/agent_action.rb', line 110
def rescue_strategy
Dynflow::Action::Rescue::Skip
end
|
#run(event = nil) ⇒ 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/katello/agent_action.rb', line 30
def run(event = nil)
case event
when nil
history = dispatch_history
timeout = accept_timeout
if history.finished?
fail_on_errors
return
elsif history.accepted?
timeout = finish_timeout
end
suspend do |suspended_action|
history.dynflow_execution_plan_id = suspended_action.execution_plan_id
history.dynflow_step_id = suspended_action.step_id
history.save!
dispatch_message(history) unless input[:bulk]
schedule_timeout(timeout, optional: true)
end
when Dynflow::Action::Skip
when Dynflow::Action::Timeouts::Timeout
process_timeout
when 'accepted'
schedule_timeout(finish_timeout, optional: true)
suspend
else
fail_on_errors
end
end
|