Commit edfbcc06 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'id-make-project-cache-worker-idempotent' into 'master'

Make ProjectCacheWorker idempotent

See merge request gitlab-org/gitlab!48790
parents 2978c49f 74054fee
......@@ -1852,7 +1852,7 @@
:urgency: :high
:resource_boundary: :unknown
:weight: 1
:idempotent:
:idempotent: true
:tags: []
- :name: project_daily_statistics
:feature_category: :source_code_management
......
# frozen_string_literal: true
# Worker for updating any project specific caches.
class ProjectCacheWorker # rubocop:disable Scalability/IdempotentWorker
class ProjectCacheWorker
include ApplicationWorker
LEASE_TIMEOUT = 15.minutes.to_i
......@@ -9,6 +9,7 @@ class ProjectCacheWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :source_code_management
urgency :high
loggable_arguments 1, 2, 3
idempotent!
# project_id - The ID of the project for which to flush the cache.
# files - An Array containing extra types of files to refresh such as
......
......@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe ProjectCacheWorker do
let_it_be(:project) { create(:project, :repository) }
let(:worker) { described_class.new }
let(:project) { create(:project, :repository) }
describe '#perform' do
context 'with an existing project' do
......@@ -23,6 +24,10 @@ RSpec.describe ProjectCacheWorker do
worker.perform(project.id, %w(readme))
end
it 'is idempotent' do
expect { perform_multiple([project.id, %w(readme)]) }.not_to raise_error
end
end
end
end
......
......@@ -5,8 +5,9 @@ require 'spec_helper'
RSpec.describe ProjectCacheWorker do
include ExclusiveLeaseHelpers
let_it_be(:project) { create(:project, :repository) }
let(:worker) { described_class.new }
let(:project) { create(:project, :repository) }
let(:lease_key) { ["project_cache_worker", project.id, *statistics.sort].join(":") }
let(:lease_timeout) { ProjectCacheWorker::LEASE_TIMEOUT }
let(:statistics) { [] }
......@@ -126,4 +127,15 @@ RSpec.describe ProjectCacheWorker do
end
end
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [project.id, %w(readme), %w(repository_size)] }
it 'calls Projects::UpdateStatisticsService service twice', :clean_gitlab_redis_shared_state do
expect(Projects::UpdateStatisticsService).to receive(:new).once.and_return(double(execute: true))
expect(UpdateProjectStatisticsWorker).to receive(:perform_in).once
subject
end
end
end
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