-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from agrare/delete_worker_records_with_json_q…
…ueue_names Delete any worker records that have a JSON queue_name
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
db/migrate/20200717181436_delete_workers_with_json_queue_names.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
23 changes: 23 additions & 0 deletions
23
spec/migrations/20200717181436_delete_workers_with_json_queue_names_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |