Skip to content

Commit

Permalink
Only queue check_for_evm_snapshots zones active smartstate role
Browse files Browse the repository at this point in the history
We should only queue the Job.check_for_evm_snapshots method on zones
which have an active smartstate role.
  • Loading branch information
agrare committed Oct 16, 2023
1 parent c7e045b commit e11ec4c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def session_check_session_timeout
end

def job_check_for_evm_snapshots(job_not_found_delay)
queue_work_on_each_zone(:class_name => "Job", :method_name => "check_for_evm_snapshots", :args => [job_not_found_delay])
queue_work_on_each_zone_with_active_role(
"smartstate",
:class_name => "Job",
:method_name => "check_for_evm_snapshots",
:args => [job_not_found_delay]
)
end

def vm_scan_dispatcher_dispatch
Expand Down Expand Up @@ -207,4 +212,10 @@ def queue_work(options)
def queue_work_on_each_zone(options)
Zone.in_my_region.each { |z| queue_work(options.merge(:zone => z.name)) }
end

def queue_work_on_each_zone_with_active_role(role_name, options)
Zone.in_my_region
.select { |z| z.role_active?(role_name) }
.each { |z| queue_work(options.merge(:zone => z.name)) }
end
end
22 changes: 22 additions & 0 deletions spec/models/miq_schedule_worker/jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,27 @@
expect(MiqQueue.where(:method_name => "log_config").first).to have_attributes(:queue_name => "miq_server", :server_guid => guid, :zone => zone.name, :priority => MiqQueue::MEDIUM_PRIORITY)
end
end

describe "#job_check_for_evm_snapshots" do
context "with no zones having an active smartstate role" do
it "doesn't queue any work" do
described_class.new.job_check_for_evm_snapshots(1.hour)
expect(MiqQueue.count).to be_zero
end
end

context "with a zone having an active smartstate role" do
let(:role) { ServerRole.find_by(:name => "smartstate") || FactoryBot.create(:server_role, :name => 'smartstate', :max_concurrent => 0) }
before do
server.assign_role(role).update(:active => true)
end

it "doesn't queue any work" do
described_class.new.job_check_for_evm_snapshots(1.hour)
expect(MiqQueue.count).to eq(1)
expect(MiqQueue.where(:class_name => "Job", :method_name => "check_for_evm_snapshots").first).to have_attributes(:queue_name => "generic", :zone => zone.name, :priority => MiqQueue::MEDIUM_PRIORITY)
end
end
end
end
end

0 comments on commit e11ec4c

Please sign in to comment.