Skip to content

Commit ccfb65d

Browse files
committed
Drop requirement to find worker record
1 parent 9cc1d4a commit ccfb65d

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

lib/workers/bin/run_single_worker.rb

+9-32
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def all_role_names
8282
ENV["DISABLE_MIQ_WORKER_HEARTBEAT"] ||= options[:heartbeat] ? nil : '1'
8383

8484
options[:ems_id] ||= ENV.fetch("EMS_ID", nil)
85+
options[:guid] ||= SecureRandom.uuid
8586

8687
if options[:roles].present?
8788
MiqServer.my_server.server_role_names += options[:roles]
@@ -96,45 +97,21 @@ def all_role_names
9697

9798
worker_class.preload_for_worker_role if worker_class.respond_to?(:preload_for_worker_role)
9899
unless options[:dry_run]
99-
create_options = {:pid => Process.pid}
100-
runner_options = {}
101-
102-
create_options[:system_uid] = options[:system_uid] if options[:system_uid]
103-
104-
if options[:ems_id]
105-
create_options[:queue_name] = "ems_#{options[:ems_id]}"
106-
runner_options[:ems_id] = options[:ems_id]
107-
end
108-
109-
update_options = create_options.dup
110-
# If a guid is provided, raise if it's not found, update otherwise
111-
# Because podified needs to create on the first run_single_worker and update after:
112-
# If system_uid is provided, update if found, create if not found.
113-
# TODO: This is really inconsistent and confusing. Why can't GUID follow the same rules?
114-
worker = if options[:guid]
115-
worker_class.find_by!(:guid => options[:guid]).tap do |wrkr|
116-
wrkr.update(update_options)
117-
end
118-
elsif options[:system_uid] && worker = worker_class.find_by(:system_uid => options[:system_uid])
119-
worker.update(update_options)
120-
worker
121-
else
122-
worker_class.create_worker_record(create_options)
123-
end
100+
runner_options = {:guid => options[:guid]}
101+
runner_options[:ems_id] = options[:ems_id] if options[:ems_id]
124102

125103
begin
126-
runner_options[:guid] = worker.guid
127-
$log.info("Starting #{worker.class.name} with runner options #{runner_options}")
128-
worker.class::Runner.new(runner_options).tap(&:setup_sigterm_trap).start
104+
$log.info("Starting #{worker_class.name} with runner options #{runner_options}")
105+
worker_class::Runner.new(runner_options).tap(&:setup_sigterm_trap).start
129106
rescue SystemExit
130107
raise
131108
rescue Exception => err
132-
MiqWorker::Runner.safe_log(worker, "An unhandled error has occurred: #{err}\n#{err.backtrace.join("\n")}", :error)
109+
#MiqWorker::Runner.safe_log(worker, "An unhandled error has occurred: #{err}\n#{err.backtrace.join("\n")}", :error)
133110
STDERR.puts("ERROR: An unhandled error has occurred: #{err}. See log for details.") rescue nil
134111
exit 1
135112
ensure
136-
FileUtils.rm_f(worker.heartbeat_file)
137-
$log.info("Deleting worker record for #{worker.class.name}, id #{worker.id}")
138-
worker.delete
113+
#FileUtils.rm_f(worker.heartbeat_file)
114+
$log.info("Deleting worker record for #{worker_class.name}, GUID #{options[:guid]}")
115+
#worker.delete
139116
end
140117
end

0 commit comments

Comments
 (0)