-
Notifications
You must be signed in to change notification settings - Fork 900
/
Copy pathstop.rb
47 lines (40 loc) · 1.4 KB
/
stop.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module MiqServer::WorkerManagement::Monitor::Stop
extend ActiveSupport::Concern
def clean_stop_worker_queue_items
MiqQueue.where(
:class_name => self.class.name,
:method_name => "stop_worker",
:queue_name => 'miq_server',
:server_guid => guid
).destroy_all
end
def stop_worker_queue(worker, monitor_status = :waiting_for_stop, monitor_reason = nil)
MiqQueue.put_deprecated(
:class_name => self.class.name,
:instance_id => id,
:method_name => 'stop_worker',
:args => [worker.id, monitor_status, monitor_reason],
:queue_name => 'miq_server',
:zone => zone.name,
:server_guid => guid
)
end
def stop_worker(worker, monitor_status = :waiting_for_stop, monitor_reason = nil)
w = worker.kind_of?(Integer) ? miq_workers.find_by(:id => worker) : worker
if w.nil?
_log.warn("Cannot find Worker <#{w.inspect}>")
return
end
msg = "Stopping #{w.format_full_log_msg}, status [#{w.status}]..."
_log.info(msg)
MiqEvent.raise_evm_event_queue(self, "evm_worker_stop", :event_details => msg, :type => w.type)
worker_set_monitor_status(w.pid, monitor_status)
worker_set_monitor_reason(w.pid, monitor_reason)
if w.respond_to?(:terminate)
w.terminate
else
w.update_attributes(:status => MiqWorker::STATUS_STOPPING)
worker_set_message(w, 'exit')
end
end
end