Skip to content

Commit

Permalink
Allow using existing guid for run_single_worker
Browse files Browse the repository at this point in the history
When running single workers in the context of a worker monitor, the
worker records are usually already created by the monitor process by the
time the worker is forked/spawned.

Allowing the lib/worker/bin/run_single_worker.rb script to pass a guid
allows it to use those records instead of creating new ones.  If this
option isn't used, the already created ones exist along side the other
worker records, and cause evm:stop to not function properly.
  • Loading branch information
NickLaMuro authored and jrafanie committed Jun 16, 2017
1 parent 6d3362f commit 3f3a823
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/workers/bin/run_single_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
options[:dry_run] = val
end

opts.on("-g=GUID", "--guid=GUID", "Find an existing worker record instead of creating") do |val|
options[:guid] = val
end

opts.on("-h", "--help", "Displays this help") do
puts opts
exit
Expand Down Expand Up @@ -52,7 +56,12 @@
worker_class = worker_class.constantize
worker_class.before_fork
unless options[:dry_run]
worker = worker_class.create_worker_record
worker = if options[:guid]
worker_class.find_by!(:guid => options[:guid])
else
worker_class.create_worker_record
end

begin
worker.class::Runner.start_worker(:guid => worker.guid)
ensure
Expand Down

0 comments on commit 3f3a823

Please sign in to comment.