diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index afd892658dc..d65395380d6 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -217,6 +217,12 @@ module Ci end end + def invalidate_build_cache!(build) + if can_pick?(build) + tick_runner_queue + end + end + private def cleanup_runner_queue diff --git a/app/services/ci/update_build_queue_service.rb b/app/services/ci/update_build_queue_service.rb index ab81766abf3..05dbebc4f8d 100644 --- a/app/services/ci/update_build_queue_service.rb +++ b/app/services/ci/update_build_queue_service.rb @@ -16,7 +16,7 @@ module Ci def tick_for(build, runners) runners.each do |runner| - runner.tick_runner_queue if runner.can_pick?(build) + runner.invalidate_build_cache!(build) end end end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 3e85e3c92e3..23e18efea70 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -858,4 +858,30 @@ describe Ci::Runner do end end end + + describe '#invalidate_build_cache!' do + context 'runner can pick the build' do + it 'calls #tick_runner_queue' do + ci_build = build :ci_build + runner = build :ci_runner + allow(runner).to receive(:can_pick?).with(ci_build).and_return(true) + + expect(runner).to receive(:tick_runner_queue) + + runner.invalidate_build_cache!(ci_build) + end + end + + context 'runner cannot pick the build' do + it 'does not call #tick_runner_queue' do + ci_build = build :ci_build + runner = build :ci_runner + allow(runner).to receive(:can_pick?).with(ci_build).and_return(false) + + expect(runner).not_to receive(:tick_runner_queue) + + runner.invalidate_build_cache!(ci_build) + end + end + end end