Class: SidekiqRobustJob::UniquenessStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_robust_job/uniqueness_strategy.rb,
lib/sidekiq_robust_job/uniqueness_strategy/base.rb,
lib/sidekiq_robust_job/uniqueness_strategy/no_uniqueness.rb,
lib/sidekiq_robust_job/uniqueness_strategy/until_executed.rb,
lib/sidekiq_robust_job/uniqueness_strategy/until_executing.rb,
lib/sidekiq_robust_job/uniqueness_strategy/while_executing.rb

Defined Under Namespace

Classes: Base, NoUniqueness, UnknownStrategyError, UntilExecuted, UntilExecuting, WhileExecuting

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locker:, lock_ttl_proc:, jobs_repository:, memory_monitor:) ⇒ UniquenessStrategy

Returns a new instance of UniquenessStrategy.



22
23
24
25
26
27
# File 'lib/sidekiq_robust_job/uniqueness_strategy.rb', line 22

def initialize(locker:, lock_ttl_proc:, jobs_repository:, memory_monitor:)
  @locker = locker
  @lock_ttl_proc = lock_ttl_proc
  @jobs_repository = jobs_repository
  @memory_monitor = memory_monitor
end

Class Method Details

.no_uniquenessObject



3
4
5
# File 'lib/sidekiq_robust_job/uniqueness_strategy.rb', line 3

def self.no_uniqueness
  :no_uniqueness
end

.until_executedObject



11
12
13
# File 'lib/sidekiq_robust_job/uniqueness_strategy.rb', line 11

def self.until_executed
  :until_executed
end

.until_executingObject



7
8
9
# File 'lib/sidekiq_robust_job/uniqueness_strategy.rb', line 7

def self.until_executing
  :until_executing
end

.while_executingObject



15
16
17
# File 'lib/sidekiq_robust_job/uniqueness_strategy.rb', line 15

def self.while_executing
  :while_executing
end

Instance Method Details

#resolve(strategy) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sidekiq_robust_job/uniqueness_strategy.rb', line 29

def resolve(strategy)
  case strategy.to_sym
  when SidekiqRobustJob::UniquenessStrategy.no_uniqueness
    SidekiqRobustJob::UniquenessStrategy::NoUniqueness.new(
      locker: locker,
      lock_ttl_proc: lock_ttl_proc,
      jobs_repository: jobs_repository,
      memory_monitor: memory_monitor
    )
  when SidekiqRobustJob::UniquenessStrategy.until_executing
    SidekiqRobustJob::UniquenessStrategy::UntilExecuting.new(
      locker: locker,
      lock_ttl_proc: lock_ttl_proc,
      jobs_repository: jobs_repository,
      memory_monitor: memory_monitor
    )
  when SidekiqRobustJob::UniquenessStrategy.until_executed
    SidekiqRobustJob::UniquenessStrategy::UntilExecuted.new(
      locker: locker,
      lock_ttl_proc: lock_ttl_proc,
      jobs_repository: jobs_repository,
      memory_monitor: memory_monitor
    )
  when SidekiqRobustJob::UniquenessStrategy.while_executing
    SidekiqRobustJob::UniquenessStrategy::WhileExecuting.new(
      locker: locker,
      lock_ttl_proc: lock_ttl_proc,
      jobs_repository: jobs_repository,
      memory_monitor: memory_monitor
    )
  else
    raise UnknownStrategyError.new(strategy)
  end
end