Module: SidekiqUniqueJobs::OptionsWithFallback

Included in:
Client::Middleware, Server::Middleware
Defined in:
lib/sidekiq_unique_jobs/options_with_fallback.rb

Overview

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)

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#lockSidekiqUniqueJobs::Lock::BaseLock

Check if we should log duplicate payloads



44
45
46
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 44

def lock
  @lock ||= lock_class.new(item, after_unlock_hook, @redis_pool)
end

#lock_classSidekiqUniqueJobs::Lock::BaseLock

Check if we should log duplicate payloads



50
51
52
53
54
55
56
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 50

def lock_class
  @lock_class ||= begin
    LOCKS.fetch(lock_type.to_sym) do
      fail UnknownLock, "No implementation for `lock: :#{lock_type}`"
    end
  end
end

#lock_typeSymbol



59
60
61
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 59

def lock_type
  @lock_type ||= options[LOCK_KEY] || item[LOCK_KEY] || unique_type
end

#log_duplicate_payload?Boolean

Check if we should log duplicate payloads



38
39
40
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 38

def log_duplicate_payload?
  options[LOG_DUPLICATE_KEY] || item[LOG_DUPLICATE_KEY]
end

#optionsObject



67
68
69
70
71
72
73
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 67

def options
  @options ||= begin
    opts = default_worker_options.dup
    opts.merge!(worker_options) if sidekiq_worker_class?
    (opts || {}).stringify_keys
  end
end

#unique_disabled?Boolean

Check if unique has been disabled



33
34
35
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 33

def unique_disabled?
  !unique_enabled?
end

#unique_enabled?true, false

Check if unique has been enabled



28
29
30
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 28

def unique_enabled?
  SidekiqUniqueJobs.config.enabled && lock_type
end

#unique_typeObject



63
64
65
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 63

def unique_type
  options[UNIQUE_KEY] || item[UNIQUE_KEY]
end