Commit 85e13edd authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'duplicate-jobs-with-strategies-none' into 'master'

Add :none strategy for deduplicating Sidekiq jobs

See merge request gitlab-org/gitlab!42095
parents a1f13438 b11a7e30
...@@ -7,7 +7,8 @@ module Gitlab ...@@ -7,7 +7,8 @@ module Gitlab
UnknownStrategyError = Class.new(StandardError) UnknownStrategyError = Class.new(StandardError)
STRATEGIES = { STRATEGIES = {
until_executing: UntilExecuting until_executing: UntilExecuting,
none: None
}.freeze }.freeze
def self.for(name) def self.for(name)
......
# frozen_string_literal: true
module Gitlab
module SidekiqMiddleware
module DuplicateJobs
module Strategies
# This strategy will never deduplicate a job
class None
def initialize(_duplicate_job)
end
def schedule(_job)
yield
end
def perform(_job)
yield
end
end
end
end
end
end
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::None do
let(:fake_duplicate_job) do
instance_double(Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob)
end
subject(:strategy) { described_class.new(fake_duplicate_job) }
describe '#schedule' do
it 'yields without checking for duplicates', :aggregate_failures do
expect(fake_duplicate_job).not_to receive(:scheduled?)
expect(fake_duplicate_job).not_to receive(:duplicate?)
expect(fake_duplicate_job).not_to receive(:check!)
expect { |b| strategy.schedule({}, &b) }.to yield_control
end
end
describe '#perform' do
it 'does not delete any locks before executing', :aggregate_failures do
expect(fake_duplicate_job).not_to receive(:delete!)
expect { |b| strategy.perform({}, &b) }.to yield_control
end
end
end
...@@ -8,6 +8,10 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies do ...@@ -8,6 +8,10 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies do
expect(described_class.for(:until_executing)).to eq(described_class::UntilExecuting) expect(described_class.for(:until_executing)).to eq(described_class::UntilExecuting)
end end
it 'returns the right class for `none`' do
expect(described_class.for(:none)).to eq(described_class::None)
end
it 'raises an UnknownStrategyError when passing an unknown key' do it 'raises an UnknownStrategyError when passing an unknown key' do
expect { described_class.for(:unknown) }.to raise_error(described_class::UnknownStrategyError) expect { described_class.for(:unknown) }.to raise_error(described_class::UnknownStrategyError)
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