Commit 1d07fb38 authored by Maxime Orefice's avatar Maxime Orefice Committed by Dylan Griffith

Update Ci::PendingBuild async when shared runner is toggled

parent 24946c7e
......@@ -8,7 +8,7 @@ module Groups
validate_params
update_shared_runners
update_pending_builds!
update_pending_builds_async
success
......@@ -28,12 +28,18 @@ module Groups
group.update_shared_runners_setting!(params[:shared_runners_setting])
end
def update_pending_builds!
return unless group.previous_changes.include?('shared_runners_enabled')
def update_pending_builds?
group.previous_changes.include?('shared_runners_enabled')
end
def update_pending_builds_async
return unless update_pending_builds?
update_params = { instance_runners_enabled: group.shared_runners_enabled }
group.run_after_commit_or_now do |group|
pending_builds_params = { instance_runners_enabled: group.shared_runners_enabled }
::Ci::UpdatePendingBuildService.new(group, update_params).execute
::Ci::UpdatePendingBuildService.new(group, pending_builds_params).execute
end
end
end
end
......@@ -63,6 +63,8 @@ RSpec.describe Groups::UpdateSharedRunnersService do
let_it_be(:pending_build_2) { create(:ci_pending_build, project: project, instance_runners_enabled: false) }
it 'updates pending builds for the group' do
expect(::Ci::UpdatePendingBuildService).to receive(:new).and_call_original
subject
expect(pending_build_1.reload.instance_runners_enabled).to be_truthy
......@@ -73,6 +75,8 @@ RSpec.describe Groups::UpdateSharedRunnersService do
let(:params) { { shared_runners_setting: 'invalid_enabled' } }
it 'does not update pending builds for the group' do
expect(::Ci::UpdatePendingBuildService).not_to receive(:new).and_call_original
subject
expect(pending_build_1.reload.instance_runners_enabled).to be_falsey
......@@ -99,6 +103,8 @@ RSpec.describe Groups::UpdateSharedRunnersService do
let_it_be(:pending_build_2) { create(:ci_pending_build, project: project, instance_runners_enabled: true) }
it 'updates pending builds for the group' do
expect(::Ci::UpdatePendingBuildService).to receive(:new).and_call_original
subject
expect(pending_build_1.reload.instance_runners_enabled).to be_falsey
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment