Class: SidekiqUniqueJobs::Lock::BaseLock Abstract
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::Lock::BaseLock
- Includes:
- SidekiqUniqueJobs::Logging
- Defined in:
- lib/sidekiq_unique_jobs/lock/base_lock.rb
Overview
Abstract base class for locks
Direct Known Subclasses
UntilAndWhileExecuting, UntilExecuted, UntilExecuting, WhileExecuting
Class Method Summary collapse
-
.validate_options(options = {}) ⇒ void
Validates that the sidekiq_options for the worker is valid.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the job from redis if it is locked.
-
#delete! ⇒ Object
Forcefully deletes the job from redis.
-
#execute ⇒ Object
Execute the job in the Sidekiq server processor.
-
#initialize(item, callback, redis_pool = nil) ⇒ BaseLock
constructor
A new instance of BaseLock.
-
#lock { ... } ⇒ String?
Locks a sidekiq job.
-
#locked? ⇒ true, false
Checks if the item has achieved a lock.
-
#locksmith ⇒ SidekiqUniqueJobs::Locksmith
private
The lock manager/client.
-
#unlock ⇒ String, false
Unlocks the job from redis.
Methods included from SidekiqUniqueJobs::Logging
included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context
Constructor Details
#initialize(item, callback, redis_pool = nil) ⇒ BaseLock
Returns a new instance of BaseLock.
26 27 28 29 30 31 32 33 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 26 def initialize(item, callback, redis_pool = nil) @item = item @callback = callback @redis_pool = redis_pool @attempt = 0 prepare_item # Used to ease testing @lock_config = LockConfig.new(item) end |
Class Method Details
Instance Method Details
#delete ⇒ Object
Deletes the job from redis if it is locked.
64 65 66 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 64 def delete locksmith.delete # Soft delete (don't forcefully remove when expiration is set) end |
#delete! ⇒ Object
Forcefully deletes the job from redis.
This is good for jobs when a previous lock was not unlocked
70 71 72 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 70 def delete! locksmith.delete! # Force delete the lock end |
#execute ⇒ Object
Execute the job in the Sidekiq server processor
52 53 54 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 52 def execute raise NotImplementedError, "##{__method__} needs to be implemented in #{self.class}" end |
#lock { ... } ⇒ String?
Will call a conflict strategy if lock can’t be achieved.
Locks a sidekiq job
44 45 46 47 48 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 44 def lock(&block) return call_strategy unless (locked_token = locksmith.lock(&block)) locked_token end |
#locked? ⇒ true, false
Checks if the item has achieved a lock
77 78 79 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 77 def locked? locksmith.locked? end |
#locksmith ⇒ SidekiqUniqueJobs::Locksmith
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The lock manager/client
87 88 89 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 87 def locksmith @locksmith ||= SidekiqUniqueJobs::Locksmith.new(item, redis_pool) end |
#unlock ⇒ String, false
Unlocks the job from redis
59 60 61 |
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 59 def unlock locksmith.unlock # Only signal to release the lock end |