Module: SidekiqUniqueJobs::OptionsWithFallback

Included in:
Lock::WhileExecuting, 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. job_class (required, can be anything)

Author:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



12
13
14
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 12

def self.included(base)
  base.send(:include, SidekiqUniqueJobs::SidekiqWorkerMethods)
end

Instance Method Details

#lock_classClass

Returns the corresponding class for the lock_type

Returns:

  • (Class)


48
49
50
51
52
# 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_instanceLock::BaseLock

A new lock for this Sidekiq Job

Returns:



38
39
40
# 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_typeSymbol

The type of lock for this worker

Returns:

  • (Symbol)


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

def lock_type
  @lock_type ||= options[LOCK] || item[LOCK]
end

#locksObject

A convenience method for using the configured locks



17
18
19
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 17

def locks
  SidekiqUniqueJobs.locks
end

#optionsHash<String, Object>

The default options with any matching keys overridden from worker options

Returns:

  • (Hash<String, Object>)


70
71
72
73
74
75
76
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 70

def options
  @options ||= begin
    opts = default_job_options.dup
    opts.merge!(job_options) if sidekiq_job_class?
    (opts || {}).stringify_keys
  end
end

#unique_disabled?Boolean

Check if unique has been disabled

Returns:

  • (Boolean)


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

def unique_disabled?
  !unique_enabled?
end

#unique_enabled?true, false

Check if unique has been enabled

Returns:

  • (true, false)

    indicate if the gem has been enabled



23
24
25
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 23

def unique_enabled?
  SidekiqUniqueJobs.enabled? && lock_type
end