module SidekiqUniqueJobs::OptionsWithFallback

Module containing methods shared between client and server middleware

Requires the following methods to be defined in the including class

1. item (required)
2. options (can be nil)
3. worker_class (required, can be anything)

@author Mikael Henriksson <mikael@mhenrixon.com>

Public Class Methods

included(base) click to toggle source
# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 12
def self.included(base)
  base.send(:include, SidekiqUniqueJobs::SidekiqWorkerMethods)
end

Public Instance Methods

lock_class() click to toggle source

Returns the corresponding class for the lock_type

@return [Class]

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 48
def lock_class
  @lock_class ||= locks.fetch(lock_type.to_sym) do
    raise UnknownLock, "No implementation for `lock: :#{lock_type}`"
  end
end
lock_instance() click to toggle source

A new lock for this Sidekiq Job

@return [Lock::BaseLock] an instance of a lock implementation

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 38
def lock_instance
  @lock_instance ||= lock_class.new(item, after_unlock_hook, @redis_pool)
end
lock_type() click to toggle source

The type of lock for this worker

@return [Symbol]

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 60
def lock_type
  @lock_type ||= options[LOCK] || item[LOCK]
end
locks() click to toggle source

A convenience method for using the configured locks

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 17
def locks
  SidekiqUniqueJobs.locks
end
options() click to toggle source

The default options with any matching keys overridden from worker options

@return [Hash<String, Object>]

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 70
def options
  @options ||= begin
    opts = default_worker_options.dup
    opts.merge!(worker_options) if sidekiq_worker_class?
    (opts || {}).stringify_keys
  end
end
unique_disabled?() click to toggle source

Check if unique has been disabled

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 28
def unique_disabled?
  !unique_enabled?
end
unique_enabled?() click to toggle source

Check if unique has been enabled @return [true, false] indicate if the gem has been enabled

# File lib/sidekiq_unique_jobs/options_with_fallback.rb, line 23
def unique_enabled?
  SidekiqUniqueJobs.enabled? && lock_type
end