Commit b11a7e30 authored by Marius Bobin's avatar Marius Bobin

Add :none strategy for deduplicating Sidekiq jobs

Allows a job not to be deduplicated even though it is idempotent:

```ruby
  class DummyWorker
    include ApplicationWorker

    deduplicate :none
    idempotent!

    # ...
  end
```
parent e550811c
......@@ -7,7 +7,8 @@ module Gitlab
UnknownStrategyError = Class.new(StandardError)
STRATEGIES = {
until_executing: UntilExecuting
until_executing: UntilExecuting,
none: None
}.freeze
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
expect(described_class.for(:until_executing)).to eq(described_class::UntilExecuting)
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
expect { described_class.for(:unknown) }.to raise_error(described_class::UnknownStrategyError)
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