Skip to content

Commit

Permalink
Merge pull request #14638 from jrafanie/fix_worker_monitor_drb_new_cl…
Browse files Browse the repository at this point in the history
…ient_each_time

Make worker_monitor_drb act like a reader again!
  • Loading branch information
gtanzillo authored Apr 4, 2017
2 parents cb39482 + a9726db commit 56ee45a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
29 changes: 15 additions & 14 deletions app/models/miq_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,21 @@ def my_monitor_started?
end

def worker_monitor_drb
raise _("%{log} No MiqServer found to establishing DRb Connection to") % {:log => log_prefix} if server.nil?
drb_uri = server.reload.drb_uri
if drb_uri.blank?
raise _("%{log} Blank DRb_URI for MiqServer with ID=[%{number}], NAME=[%{name}], PID=[%{pid_number}], GUID=[%{guid_number}]") %
{:log => log_prefix,
:number => server.id,
:name => server.name,
:pid_number => server.pid,
:guid_number => server.guid}
@worker_monitor_drb ||= begin
raise _("%{log} No MiqServer found to establishing DRb Connection to") % {:log => log_prefix} if server.nil?
drb_uri = server.reload.drb_uri
if drb_uri.blank?
raise _("%{log} Blank DRb_URI for MiqServer with ID=[%{number}], NAME=[%{name}], PID=[%{pid_number}], GUID=[%{guid_number}]") %
{:log => log_prefix,
:number => server.id,
:name => server.name,
:pid_number => server.pid,
:guid_number => server.guid}
end
_log.info("#{log_prefix} Initializing DRb Connection to MiqServer with ID=[#{server.id}], NAME=[#{server.name}], PID=[#{server.pid}], GUID=[#{server.guid}] DRb URI=[#{drb_uri}]")
require 'drb'
DRbObject.new(nil, drb_uri)
end
_log.info("#{log_prefix} Initializing DRb Connection to MiqServer with ID=[#{server.id}], NAME=[#{server.name}], PID=[#{server.pid}], GUID=[#{server.guid}] DRb URI=[#{drb_uri}]")
require 'drb'
DRbObject.new(nil, drb_uri)
end

###############################
Expand Down Expand Up @@ -355,8 +357,7 @@ def heartbeat
now = Time.now.utc
# Heartbeats can be expensive, so do them only when needed
return if @last_hb.kind_of?(Time) && (@last_hb + worker_settings[:heartbeat_freq]) >= now
@worker_monitor_drb ||= worker_monitor_drb
messages = @worker_monitor_drb.worker_heartbeat(@worker.pid, @worker.class.name, @worker.queue_name)
messages = worker_monitor_drb.worker_heartbeat(@worker.pid, @worker.class.name, @worker.queue_name)
@last_hb = now
messages.each { |msg, *args| process_message(msg, *args) }
do_heartbeat_work
Expand Down
8 changes: 8 additions & 0 deletions spec/models/miq_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@
allow(@worker_base).to receive(:run).and_raise(SignalException, "SIGALRM")
expect { @worker_base.start }.to raise_error(SignalException, "SIGALRM")
end

it "worker_monitor_drb caches DRbObject" do
@worker_base.instance_variable_set(:@server, FactoryGirl.create(:miq_server, :drb_uri => "druby://127.0.0.1:123456"))
require 'drb'
allow(DRbObject).to receive(:new).and_return(0, 1)
expect(@worker_base.worker_monitor_drb).to eq 0
expect(@worker_base.worker_monitor_drb).to eq 0
end
end
end

0 comments on commit 56ee45a

Please sign in to comment.