Skip to content
Snippets Groups Projects
Commit 7a4d723e authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Remove the key from the queue when runner is deleted

parent 7a109402
No related branches found
No related tags found
1 merge request!8664Prefer service object over after_save hook
Pipeline #
Loading
@@ -38,6 +38,8 @@ module Ci
Loading
@@ -38,6 +38,8 @@ module Ci
   
acts_as_taggable acts_as_taggable
   
after_destroy :cleanup_runner_queue
# Searches for runners matching the given query. # Searches for runners matching the given query.
# #
# This method uses ILIKE on PostgreSQL and LIKE on MySQL. # This method uses ILIKE on PostgreSQL and LIKE on MySQL.
Loading
@@ -143,6 +145,12 @@ module Ci
Loading
@@ -143,6 +145,12 @@ module Ci
   
private private
   
def cleanup_runner_queue
Gitlab::Redis.with do |redis|
redis.del(runner_queue_key)
end
end
def runner_queue_key def runner_queue_key
"runner:build_queue:#{self.token}" "runner:build_queue:#{self.token}"
end end
Loading
Loading
Loading
@@ -319,6 +319,25 @@ describe Ci::Runner, models: true do
Loading
@@ -319,6 +319,25 @@ describe Ci::Runner, models: true do
end end
end end
   
describe '#destroy' do
let(:runner) { create(:ci_runner) }
context 'when there is a tick in the queue' do
let!(:queue_key) { runner.send(:runner_queue_key) }
before do
runner.tick_runner_queue
runner.destroy
end
it 'cleans up the queue' do
Gitlab::Redis.with do |redis|
expect(redis.get(queue_key)).to be_nil
end
end
end
end
describe '.assignable_for' do describe '.assignable_for' do
let(:runner) { create(:ci_runner) } let(:runner) { create(:ci_runner) }
let(:project) { create(:project) } let(:project) { create(:project) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment