Handle pid in run_single_worker.rb properly #15820
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In classes that inherit from MiqQueueWorkerBase, they will fetch images using
MiqQueue.get
. Part of what is done in that is callingMiqWorker.my_worker
. This basically makes a call to find a worker with thepid
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 byrun_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 theMiqServer
, so this is just making therun_single_worker.rb
handle setting the pid as well.Steps for Testing/QA
Apply the following diff (needed so the
MiqGenericWorker
boots properly, and adds some handy debugging output):Start a worker using the run_single_worker.rb script:
$ ruby lib/workers/bin/run_single_worker.rb MiqGenericWorker
In a seperate tab, run an
rails console
with the following commands:You should see
handler_type
andhandler_id
fields properly set toMiqWorker
and theid
of the worker currently running (versus setting it to the server).You can also run this using an existing worker by calling
MiqGenericWorker.create_worker_record
, grabbing the resultingguid
, and then running therun_single_worker.rb
script from above with the--guid [GUID_FROM_BEFORE]
option. Then any jobs queued and picked up will then be using the handler of that worker created in the console.