Sha256: 5c66e736f293ce35e459c12ea67d1b7af80f6f908e4a8296fe3330da2874af6c
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true module SidekiqUniqueJobs # Shared logic for dealing with options # This class requires 3 things to be defined in the class including it # 1. item (required) # 2. options (can be nil) # 3. worker_class (required, can be anything) module OptionsWithFallback LOCKS = { until_and_while_executing: SidekiqUniqueJobs::Lock::UntilAndWhileExecuting, until_executed: SidekiqUniqueJobs::Lock::UntilExecuted, until_executing: SidekiqUniqueJobs::Lock::UntilExecuting, until_expired: SidekiqUniqueJobs::Lock::UntilExpired, until_timeout: SidekiqUniqueJobs::Lock::UntilExpired, while_executing: SidekiqUniqueJobs::Lock::WhileExecuting, while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject, }.freeze def self.included(base) base.send(:include, SidekiqUniqueJobs::SidekiqWorkerMethods) end def unique_enabled? SidekiqUniqueJobs.config.enabled && lock_type end def unique_disabled? !unique_enabled? end def log_duplicate_payload? options[LOG_DUPLICATE_KEY] || item[LOG_DUPLICATE_KEY] end def lock @lock ||= lock_class.new(item, @redis_pool) end def lock_class @lock_class ||= begin LOCKS.fetch(lock_type.to_sym) do fail UnknownLock, "No implementation for `unique: :#{lock_type}`" end end end def lock_type @lock_type ||= options[UNIQUE_KEY] || item[UNIQUE_KEY] end def options @options ||= begin opts = default_worker_options.dup opts.merge!(worker_options) if sidekiq_worker_class? (opts || {}).stringify_keys end end end end
Version data entries
3 entries across 3 versions & 1 rubygems