Commit a264e003 authored by Igor Drozdov's avatar Igor Drozdov

Make RepositoryUpdateRemoteMirrorWorker idempotent

The job can be run multiple times with the same params
without side effects.
parent fc5df2d4
...@@ -2021,7 +2021,7 @@ ...@@ -2021,7 +2021,7 @@
:urgency: :low :urgency: :low
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 1 :weight: 1
:idempotent: :idempotent: true
:tags: [] :tags: []
- :name: self_monitoring_project_create - :name: self_monitoring_project_create
:feature_category: :metrics :feature_category: :metrics
......
# frozen_string_literal: true # frozen_string_literal: true
class RepositoryUpdateRemoteMirrorWorker # rubocop:disable Scalability/IdempotentWorker class RepositoryUpdateRemoteMirrorWorker
UpdateError = Class.new(StandardError) UpdateError = Class.new(StandardError)
include ApplicationWorker include ApplicationWorker
...@@ -11,6 +11,7 @@ class RepositoryUpdateRemoteMirrorWorker # rubocop:disable Scalability/Idempoten ...@@ -11,6 +11,7 @@ class RepositoryUpdateRemoteMirrorWorker # rubocop:disable Scalability/Idempoten
sidekiq_options retry: 3, dead: false sidekiq_options retry: 3, dead: false
feature_category :source_code_management feature_category :source_code_management
loggable_arguments 1 loggable_arguments 1
idempotent!
LOCK_WAIT_TIME = 30.seconds LOCK_WAIT_TIME = 30.seconds
MAX_TRIES = 3 MAX_TRIES = 3
......
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_state do RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_state do
subject { described_class.new } let_it_be(:remote_mirror) { create(:remote_mirror) }
let(:remote_mirror) { create(:remote_mirror) }
let(:scheduled_time) { Time.current - 5.minutes } let(:scheduled_time) { Time.current - 5.minutes }
around do |example| around do |example|
...@@ -19,6 +18,8 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st ...@@ -19,6 +18,8 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st
end end
describe '#perform' do describe '#perform' do
subject { described_class.new }
it 'calls out to the service to perform the update' do it 'calls out to the service to perform the update' do
expect_mirror_service_to_return(remote_mirror, status: :success) expect_mirror_service_to_return(remote_mirror, status: :success)
...@@ -68,4 +69,8 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st ...@@ -68,4 +69,8 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st
subject.perform(remote_mirror.id, scheduled_time) subject.perform(remote_mirror.id, scheduled_time)
end end
end end
include_examples 'an idempotent worker' do
let(:job_args) { [remote_mirror.id, scheduled_time] }
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