Handle SIGTERM in run_single_worker.rb #15818
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.
Termination of workers via the
MiqServer::WorkerManager
currently happens by sending a exit message over DRB to the worker that it will process in between doing jobs (so nothing is halfway in flight). TheMiqServer
will wait for a specific amount of time (timeout defined in the settings, but defaults to5.minutes
or so usually) before killing it (at this point, it is assumed the worker is stuck).Currently,
SIGTERMS
are trapped and handled by the worker runner class to run thedo_exit
method, but they don't allow the work currently in progress to finish. The addition of the#setup_sigterm_trap
method will introduceKernel
traps that properly inform the worker that once they have finished with their next round of work, they should exit.Steps for Testing/QA
Apply the following diff (needed becuase the VimBroker won't be present, and adds some handy debugging output):
Create some long running work for your worker to act on (the time it sleeps in
:args
can be adjusted as needed):$ bin/rails runner 'MiqQueue.put :class_name => "Kernel", :method_name => "sleep", :args => 200, :zone => MiqServer.my_server.zone.name, :queue_name => "generic"'
Start a worker using the
run_single_worker.rb
script:$ ruby lib/workers/bin/run_single_worker.rb MiqGenericWorker
Wait for the worker to start processing the job, then interrupt it (Crtl-C).
The worker should output
done!
before exiting.