Commit 1d774e4e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Mark ScheduleAggregationWorker as idempotent

This marks the Namespaces::ScheduleAggregationWorker as
idempotent. It was already idempotent, because it checks the existence
of the Namespace::AggregationSchedule before doing anything and it
uses `safe_find_or_create` to avoid race conditions.

This adds specs proving that it is idempotent.

It also adds the worker to the DROPPABLE_QUEUES so we can use it to
try out deduplicating jobs.
parent 259b4789
...@@ -919,7 +919,7 @@ ...@@ -919,7 +919,7 @@
:urgency: :low :urgency: :low
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 1 :weight: 1
:idempotent: :idempotent: true
- :name: authorized_keys - :name: authorized_keys
:feature_category: :source_code_management :feature_category: :source_code_management
:has_external_dependencies: :has_external_dependencies:
......
# frozen_string_literal: true # frozen_string_literal: true
module Namespaces module Namespaces
class ScheduleAggregationWorker # rubocop:disable Scalability/IdempotentWorker class ScheduleAggregationWorker
include ApplicationWorker include ApplicationWorker
queue_namespace :update_namespace_statistics queue_namespace :update_namespace_statistics
feature_category :source_code_management feature_category :source_code_management
idempotent!
def perform(namespace_id) def perform(namespace_id)
return unless aggregation_schedules_table_exists? return unless aggregation_schedules_table_exists?
......
...@@ -6,7 +6,8 @@ module Gitlab ...@@ -6,7 +6,8 @@ module Gitlab
module SidekiqMiddleware module SidekiqMiddleware
module DuplicateJobs module DuplicateJobs
DROPPABLE_QUEUES = Set.new([ DROPPABLE_QUEUES = Set.new([
Namespaces::RootStatisticsWorker.queue Namespaces::RootStatisticsWorker.queue,
Namespaces::ScheduleAggregationWorker.queue
]).freeze ]).freeze
def self.drop_duplicates?(queue_name) def self.drop_duplicates?(queue_name)
......
...@@ -54,6 +54,17 @@ describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_ ...@@ -54,6 +54,17 @@ describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_
end end
end end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [group.id] }
it 'creates a single aggregation schedule' do
expect { worker.perform(*job_args) }
.to change { Namespace::AggregationSchedule.count }.by(1)
expect { worker.perform(*job_args) }
.not_to change { Namespace::AggregationSchedule.count }
end
end
def stub_aggregation_schedule_statistics def stub_aggregation_schedule_statistics
# Namespace::Aggregations are deleted by # Namespace::Aggregations are deleted by
# Namespace::AggregationSchedule::schedule_root_storage_statistics, # Namespace::AggregationSchedule::schedule_root_storage_statistics,
......
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