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 @@
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:idempotent: true
- :name: authorized_keys
:feature_category: :source_code_management
:has_external_dependencies:
......
# frozen_string_literal: true
module Namespaces
class ScheduleAggregationWorker # rubocop:disable Scalability/IdempotentWorker
class ScheduleAggregationWorker
include ApplicationWorker
queue_namespace :update_namespace_statistics
feature_category :source_code_management
idempotent!
def perform(namespace_id)
return unless aggregation_schedules_table_exists?
......
......@@ -6,7 +6,8 @@ module Gitlab
module SidekiqMiddleware
module DuplicateJobs
DROPPABLE_QUEUES = Set.new([
Namespaces::RootStatisticsWorker.queue
Namespaces::RootStatisticsWorker.queue,
Namespaces::ScheduleAggregationWorker.queue
]).freeze
def self.drop_duplicates?(queue_name)
......
......@@ -54,6 +54,17 @@ describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_
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
# Namespace::Aggregations are deleted by
# 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