Class: SidekiqUniqueJobs::Lock::WhileExecuting
- Defined in:
- lib/sidekiq_unique_jobs/lock/while_executing.rb
Overview
Direct Known Subclasses
Instance Method Summary collapse
-
#execute { ... } ⇒ Object
Executes in the Sidekiq server process.
-
#initialize(item, callback, redis_pool = nil) ⇒ WhileExecuting
constructor
A new instance of WhileExecuting.
-
#lock {|job_id| ... } ⇒ true
Simulate that a client lock was achieved.
Methods included from SidekiqUniqueJobs::Logging::Middleware
Methods included from SidekiqUniqueJobs::Logging
#build_message, included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context
Methods included from OptionsWithFallback
included, #lock_class, #lock_instance, #lock_type, #locks, #options, #unique_disabled?, #unique_enabled?
Methods inherited from BaseLock
Methods included from Reflectable
Constructor Details
#initialize(item, callback, redis_pool = nil) ⇒ WhileExecuting
Returns a new instance of WhileExecuting.
23 24 25 26 |
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 23 def initialize(item, callback, redis_pool = nil) super(item, callback, redis_pool) append_unique_key_suffix end |
Instance Method Details
#execute { ... } ⇒ Object
Executes in the Sidekiq server process.
These jobs are locked in the server process not from the client
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 41 def execute with_logging_context do call_strategy(origin: :server) unless locksmith.execute do yield callback_safely if locksmith.unlock ensure locksmith.unlock end end end |
#lock {|job_id| ... } ⇒ true
Simulate that a client lock was achieved.
These locks should only ever be created in the server process.
31 32 33 34 35 36 |
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 31 def lock job_id = item[JID] yield job_id if block_given? job_id end |