Module: ActiveJob::Uniqueness

Extended by:
ActiveSupport::Autoload
Defined in:
lib/active_job/uniqueness.rb,
lib/active_job/uniqueness/errors.rb,
lib/active_job/uniqueness/version.rb,
lib/active_job/uniqueness/lock_key.rb,
lib/active_job/uniqueness/strategies.rb,
lib/active_job/uniqueness/lock_manager.rb,
lib/active_job/uniqueness/configuration.rb,
lib/active_job/uniqueness/sidekiq_patch.rb,
lib/active_job/uniqueness/log_subscriber.rb,
lib/active_job/uniqueness/strategies/base.rb,
lib/active_job/uniqueness/active_job_patch.rb,
lib/active_job/uniqueness/test_lock_manager.rb,
lib/active_job/uniqueness/strategies/until_expired.rb,
lib/active_job/uniqueness/strategies/until_executed.rb,
lib/active_job/uniqueness/strategies/until_executing.rb,
lib/active_job/uniqueness/strategies/while_executing.rb,
lib/generators/active_job/uniqueness/install_generator.rb,
lib/active_job/uniqueness/strategies/until_and_while_executing.rb

Defined Under Namespace

Modules: ActiveJobPatch, Generators, SidekiqPatch, Strategies Classes: Configuration, Error, InvalidOnConflictAction, JobNotUnique, LockKey, LockManager, LogSubscriber, StrategyNotFound, TestLockManager

Constant Summary collapse

VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.configObject



26
27
28
# File 'lib/active_job/uniqueness.rb', line 26

def config
  @config ||= ActiveJob::Uniqueness::Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



22
23
24
# File 'lib/active_job/uniqueness.rb', line 22

def configure
  yield config
end

.lock_managerObject



30
31
32
# File 'lib/active_job/uniqueness.rb', line 30

def lock_manager
  @lock_manager ||= ActiveJob::Uniqueness::LockManager.new(config.redlock_servers, config.redlock_options)
end

.reset_manager!Object



42
43
44
# File 'lib/active_job/uniqueness.rb', line 42

def reset_manager!
  @lock_manager = nil
end

.test_mode!Object



38
39
40
# File 'lib/active_job/uniqueness.rb', line 38

def test_mode!
  @lock_manager = ActiveJob::Uniqueness::TestLockManager.new
end

.unlock!(**args) ⇒ Object



34
35
36
# File 'lib/active_job/uniqueness.rb', line 34

def unlock!(**args)
  lock_manager.delete_locks(ActiveJob::Uniqueness::LockKey.new(**args).wildcard_key)
end

.unlock_sidekiq_job!(job_data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_job/uniqueness/sidekiq_patch.rb', line 8

def self.unlock_sidekiq_job!(job_data)
  return unless job_data['class'] == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper' # non ActiveJob jobs

  job = ActiveJob::Base.deserialize(job_data.fetch('args').first)

  return unless job.class.lock_strategy_class

  begin
    job.send(:deserialize_arguments_if_needed)
  rescue ActiveJob::DeserializationError
    # Most probably, GlobalID fails to locate AR record (record is deleted)
  else
    ActiveJob::Uniqueness.unlock!(job_class_name: job.class.name, arguments: job.arguments)
  end
end