class SidekiqUniqueJobs::LockConfig
Gathers all configuration for a lock
which helps reduce the amount of instance variables
@author Mikael Henriksson <mikael@mhenrixon.com>
Attributes
@!attribute [r] errors
@return [Array<Hash<Symbol, Array<String>] a collection of configuration errors
@!attribute [r] job
@return [Symbol] the job class
@!attribute [r] limit
@return [Integer] the number of simultaneous locks
@!attribute [r] lock_info
@return [Boolean] indicate wether to use lock_info or not
@!attribute [r] on_conflict
@return [Symbol, Hash<Symbol, Symbol>] the strategies to use as conflict resolution
@!attribute [r] ttl
@return [Integer, nil] the time (in milliseconds) to live after successful
@!attribute [r] timeout
@return [Integer, nil] the time to wait for a lock
@!attribute [r] ttl
@return [Integer, nil] the time (in seconds) to live after successful
@!attribute [r] type
@return [Symbol] the type of lock
Public Class Methods
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 55 def self.from_worker(options) new(options.deep_stringify_keys) end
Instantiate a new lock_config based on sidekiq options in worker
@param [Hash] options sidekiq_options for worker
@return [LockConfig]
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 59 def initialize(job_hash = {}) @type = job_hash[LOCK]&.to_sym @job = SidekiqUniqueJobs.safe_constantize(job_hash[CLASS]) @limit = job_hash.fetch(LOCK_LIMIT, 1)&.to_i @timeout = job_hash.fetch(LOCK_TIMEOUT, 0)&.to_i @ttl = job_hash.fetch(LOCK_TTL) { job_hash.fetch(LOCK_EXPIRATION, nil) }.to_i @pttl = ttl * 1_000 @lock_info = job_hash.fetch(LOCK_INFO) { SidekiqUniqueJobs.config.lock_info } @on_conflict = job_hash.fetch(ON_CONFLICT, nil) @errors = job_hash.fetch(ERRORS) { {} } @on_client_conflict = job_hash[ON_CLIENT_CONFLICT] @on_server_conflict = job_hash[ON_SERVER_CONFLICT] end
Public Instance Methods
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 104 def errors_as_string return if valid? @errors_as_string ||= begin error_msg = +"\t" error_msg << errors.map { |key, val| "#{key}: :#{val}" }.join("\n\t") error_msg end end
Return a nice descriptive message with all validation errors
@return [String]
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 74 def lock_info? lock_info end
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 115 def on_client_conflict @on_client_conflict ||= if on_conflict.is_a?(Hash) on_conflict["client"] || on_conflict[:client] else on_conflict end end
the strategy to use as conflict resolution from sidekiq client
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 124 def on_server_conflict @on_server_conflict ||= if on_conflict.is_a?(Hash) on_conflict["server"] || on_conflict[:server] else on_conflict end end
the strategy to use as conflict resolution from sidekiq server
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 94 def valid? errors.empty? end
Is the configuration valid?
@return [true,false]
Source
# File lib/sidekiq_unique_jobs/lock_config.rb, line 84 def wait_for_lock? timeout.nil? || timeout.positive? end
Indicate if timeout was set
@return [true,false]