From 0c95def4af39d5e1c369f434a67ef3625370c09d Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Fri, 17 Jul 2020 14:36:44 -0400 Subject: [PATCH] Delete any worker records that have a JSON queue_name Allowing miq_workers with a compound queue_name is a way to allow a worker to dequeue for multiple ext_management_systems at once, aka allowing an Amazon RefreshWorker to refresh the CloudManager and NetworkManager in the same worker. This has other side effects however including making it more difficult to find a worker by an EMS (e.g. when destroying the EMS) and requires that the base MiqWorker class do `JSON.parse(self[:queue_name]) rescue self[:queue_name]` Another option is to have the child managers report their queue_name for the refresh operation as the parent manager's queue_name. --- ...36_delete_workers_with_json_queue_names.rb | 11 +++++++++ ...lete_workers_with_json_queue_names_spec.rb | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 db/migrate/20200717181436_delete_workers_with_json_queue_names.rb create mode 100644 spec/migrations/20200717181436_delete_workers_with_json_queue_names_spec.rb diff --git a/db/migrate/20200717181436_delete_workers_with_json_queue_names.rb b/db/migrate/20200717181436_delete_workers_with_json_queue_names.rb new file mode 100644 index 000000000..a77d1a6dd --- /dev/null +++ b/db/migrate/20200717181436_delete_workers_with_json_queue_names.rb @@ -0,0 +1,11 @@ +class DeleteWorkersWithJsonQueueNames < ActiveRecord::Migration[5.2] + class MiqWorker < ActiveRecord::Base + include ActiveRecord::IdRegions + + self.inheritance_column = :_type_disabled + end + + def up + MiqWorker.in_my_region.where("queue_name LIKE ?", "\[%\]").delete_all + end +end diff --git a/spec/migrations/20200717181436_delete_workers_with_json_queue_names_spec.rb b/spec/migrations/20200717181436_delete_workers_with_json_queue_names_spec.rb new file mode 100644 index 000000000..720473942 --- /dev/null +++ b/spec/migrations/20200717181436_delete_workers_with_json_queue_names_spec.rb @@ -0,0 +1,23 @@ +require_migration + +describe DeleteWorkersWithJsonQueueNames do + let(:miq_worker_stub) { migration_stub(:MiqWorker) } + + migration_context :up do + it "deletes workers with a JSON type queue name" do + worker = miq_worker_stub.create!(:queue_name => "[\"ems_4\", \"ems_5\", \"ems_6\"]") + + migrate + + expect(miq_worker_stub.find_by(:id => worker.id)).to be_nil + end + + it "doesn't touch workers without JSON queue names" do + worker = miq_worker_stub.create!(:queue_name => "ems_1") + + migrate + + expect(worker.reload.queue_name).to eq("ems_1") + end + end +end