Class: SidekiqUniqueJobs::Lock::WhileExecuting
- Defined in:
- lib/sidekiq_unique_jobs/lock/while_executing.rb
Overview
Direct Known Subclasses
Constant Summary collapse
- RUN_SUFFIX =
":RUN"
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 ⇒ 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 51 52 53 54 55 |
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 41 def execute(&block) with_logging_context do executed = locksmith.execute do yield item[JID] ensure unlock_and_callback end unless executed reflect(:execution_failed, item) call_strategy(origin: :server, &block) end end end |
#lock ⇒ 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 if block_given? job_id end |