Skip to content

Commit

Permalink
Handle pid in run_single_worker.rb properly
Browse files Browse the repository at this point in the history
In classes that inherit from MiqQueueWorkerBase, they will fetch images
using `MiqQueue.get`.  Part of what is done in that is calling
`MiqWorker.my_worker`.  This basically makes a call to find a worker
with the `pid` value that matches the same pid used by the current
process.

Unfortunately, this is normally set by the `MiqServer` prior to forking
the worker, so this isn't set by `run_single_worker.rb`.

To address this, either add to the `create_options` an attribute for
`:pid` that will create a new worker with the existing pid of the
current process, or if a `:guid` is passed in, update the attributes of
the existing worker to set the pid.  This is already done by the
`MiqServer`, so this is just making the `run_single_worker.rb` handle
setting the pid as well.
  • Loading branch information
NickLaMuro committed Aug 15, 2017
1 parent 947ff80 commit f2c4abd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/workers/bin/run_single_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
worker_class = worker_class.constantize
worker_class.before_fork
unless options[:dry_run]
create_options = {}
create_options = {:pid => Process.pid}
runner_options = {}

if ENV["QUEUE"]
Expand All @@ -66,7 +66,9 @@
end

worker = if options[:guid]
worker_class.find_by!(:guid => options[:guid])
worker_class.find_by!(:guid => options[:guid]).tap do |wrkr|
wrkr.update_attributes(:pid => Process.pid)
end
else
worker_class.create_worker_record(create_options)
end
Expand Down

0 comments on commit f2c4abd

Please sign in to comment.