Allow `rake cache:clear` clearing pipeline status cache
* Use the correct key prefix * Clear old cache keys TODO: At some point we could remove clearing old cache keys.
This commit is contained in:
parent
de36ca81d3
commit
4b30aec0aa
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Now `rake cache:clear` will also clear pipeline status cache
|
||||
merge_request: 18257
|
||||
author:
|
||||
type: fixed
|
|
@ -40,7 +40,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def self.cache_key_for_project(project)
|
||||
"projects/#{project.id}/pipeline_status"
|
||||
"#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:projects/#{project.id}/pipeline_status"
|
||||
end
|
||||
|
||||
def self.update_for_pipeline(pipeline)
|
||||
|
|
|
@ -6,11 +6,15 @@ namespace :cache do
|
|||
desc "GitLab | Clear redis cache"
|
||||
task redis: :environment do
|
||||
Gitlab::Redis::Cache.with do |redis|
|
||||
cache_key_pattern = %W[#{Gitlab::Redis::Cache::CACHE_NAMESPACE}*
|
||||
projects/*/pipeline_status]
|
||||
|
||||
cache_key_pattern.each do |match|
|
||||
cursor = REDIS_SCAN_START_STOP
|
||||
loop do
|
||||
cursor, keys = redis.scan(
|
||||
cursor,
|
||||
match: "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}*",
|
||||
match: match,
|
||||
count: REDIS_CLEAR_BATCH_SIZE
|
||||
)
|
||||
|
||||
|
@ -20,6 +24,7 @@ namespace :cache do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task all: [:redis]
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do
|
||||
let!(:project) { create(:project, :repository) }
|
||||
let(:pipeline_status) { described_class.new(project) }
|
||||
let(:cache_key) { "projects/#{project.id}/pipeline_status" }
|
||||
let(:cache_key) { described_class.cache_key_for_project(project) }
|
||||
|
||||
describe '.load_for_project' do
|
||||
it "loads the status" do
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
require 'rake_helper'
|
||||
|
||||
describe 'clearing redis cache' do
|
||||
before do
|
||||
Rake.application.rake_require 'tasks/cache'
|
||||
end
|
||||
|
||||
describe 'clearing pipeline status cache' do
|
||||
let(:pipeline_status) { create(:ci_pipeline).project.pipeline_status }
|
||||
|
||||
before do
|
||||
allow(pipeline_status).to receive(:loaded).and_return(nil)
|
||||
end
|
||||
|
||||
it 'clears pipeline status cache' do
|
||||
expect { run_rake_task('cache:clear:redis') }.to change { pipeline_status.has_cache? }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue