Sha256: c7369b38a8d6c551fe2341cf7b2452353bc301e1d818133a4e90ded62020bf75

Contents?: true

Size: 983 Bytes

Versions: 4

Compression:

Stored size: 983 Bytes

Contents

require 'sidekiq_unique_jobs/middleware/client/strategies/unique'
require 'sidekiq_unique_jobs/middleware/client/strategies/testing_inline'

module SidekiqUniqueJobs
  module Middleware
    module Client
      class UniqueJobs
        STRATEGIES = [
          Strategies::TestingInline,
          Strategies::Unique
        ]

        attr_reader :item, :worker_class, :redis_pool

        def call(worker_class, item, queue, redis_pool = nil)
          @worker_class = SidekiqUniqueJobs.worker_class_constantize(worker_class)
          @item = item
          @redis_pool = redis_pool

          if unique_enabled?
            strategy.review(worker_class, item, queue, redis_pool) { yield }
          else
            yield
          end
        end

        private

        def unique_enabled?
          worker_class.get_sidekiq_options['unique'] || item['unique']
        end

        def strategy
          STRATEGIES.detect(&:elegible?)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-3.0.12 lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb
sidekiq-unique-jobs-3.0.11 lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb
sidekiq-unique-jobs-3.0.10 lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb
sidekiq-unique-jobs-3.0.9 lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb