Module: Sidekiq::LockableJob

Defined in:
lib/sidekiq/lockable_job.rb,
lib/sidekiq/lockable_job/lock_service.rb,
lib/sidekiq/lockable_job/multi_lock_service.rb,
lib/sidekiq/lockable_job/middleware/client/set_locks.rb,
lib/sidekiq/lockable_job/middleware/server/set_locks.rb,
lib/sidekiq/lockable_job/middleware/server/unset_locks.rb,
lib/sidekiq/lockable_job/middleware/server/handle_locked_by.rb

Defined Under Namespace

Modules: ClassMethods, LockService, Middleware, MultiLockService Classes: Error, LockedJobError

Constant Summary collapse

DEFAULT_LOCKABLE_JOB_SERVICE =
LockService

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sidekiq/lockable_job.rb', line 14

def self.included(base)
  unless base.ancestors.include? Sidekiq::Worker
    raise ArgumentError, "Sidekiq::LockableJob can only be included in a Sidekiq::Worker"
  end

  base.extend(ClassMethods)

  # Automatically add sidekiq middleware when we're first included
  #
  # This might only occur when the worker class is first loaded in a
  # development rails environment, but that happens before the middleware
  # chain is invoked so we're all good.
  #
  Sidekiq.configure_server do |config|
    unless config.server_middleware.exists? Sidekiq::LockableJob::Middleware::Server::SetLocks
      config.server_middleware.add Sidekiq::LockableJob::Middleware::Server::SetLocks
    end
    unless config.server_middleware.exists? Sidekiq::LockableJob::Middleware::Server::HandleLockedBy
      config.server_middleware.add Sidekiq::LockableJob::Middleware::Server::HandleLockedBy
    end
    unless config.server_middleware.exists? Sidekiq::LockableJob::Middleware::Server::UnsetLocks
      config.server_middleware.add Sidekiq::LockableJob::Middleware::Server::UnsetLocks
    end
  end
  Sidekiq.configure_client do |config|
    unless config.client_middleware.exists? Sidekiq::LockableJob::Middleware::Client::SetLocks
      config.client_middleware.add Sidekiq::LockableJob::Middleware::Client::SetLocks
    end
  end
end