Skip to content

Commit

Permalink
orchestrate_destroy for provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed Jan 5, 2018
1 parent 2cfe78b commit b70929e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/models/mixins/async_delete_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module AsyncDeleteMixin
extend ActiveSupport::Concern
included do
def self._queue_task(task, ids)
ids.each do |id|
def self._queue_task(task, ids, deliver_on = nil)
Array.wrap(ids).each do |id|
MiqQueue.put(
:class_name => name,
:instance_id => id,
:msg_timeout => 3600,
:method_name => task.to_s
:method_name => task.to_s,
:deliver_on => deliver_on,
)
end
end
Expand Down
14 changes: 14 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,18 @@ def refresh_ems(opts = {})
end
managers.flat_map { |manager| EmsRefresh.queue_refresh(manager, nil, opts) }
end

def self.destroy_queue(ids)
find(ids).each(&:destroy_queue)
end

def destroy_queue
return destroy if managers.empty?

_log.info("Queuing destroy of managers of provider: #{self.class.name} with id: #{id}")
managers.each(&:destroy_queue)

_log.info("Queuing destroy of provider: #{self.class.name} with id: #{id}")
self.class._queue_task(:destroy_queue, id, 15.seconds.from_now)
end
end
22 changes: 21 additions & 1 deletion spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe Provider do
let(:provider) { described_class.new }
let(:provider) { FactoryGirl.create(:provider) }

describe "#verify_ssl" do
context "when non set" do
Expand Down Expand Up @@ -61,4 +61,24 @@
expect(tenant.providers).to include(provider)
end
end

context "#destroy_queue" do
it "destroy when has no managers" do
provider.managers = []
expect(provider).to receive(:destroy)
provider.destroy_queue
end

it "to destroy_queue its managers and itself" do
manager = FactoryGirl.create(:ext_management_system, :zone => EvmSpecHelper.local_miq_server.zone)
provider.managers = [manager]
expect(manager).to receive(:destroy_queue)
expect(provider).not_to receive(:destroy)
provider.destroy_queue
expect(MiqQueue.find_by(:instance_id => provider.id)).to have_attributes(
'method_name' => 'destroy_queue',
'class_name' => provider.class.name,
)
end
end
end

0 comments on commit b70929e

Please sign in to comment.