Class: Sidekiq::Antidote::Inhibitor

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/antidote/inhibitor.rb

Overview

Single poison inhibition rule: class qualifier + treatment action.

Constant Summary collapse

TREATMENTS =
%w[skip kill].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, treatment:, class_qualifier:) ⇒ Inhibitor

Returns a new instance of Inhibitor.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
# File 'lib/sidekiq/antidote/inhibitor.rb', line 25

def initialize(id:, treatment:, class_qualifier:)
  @id              = -id.to_s
  @treatment       = -treatment.to_s
  @class_qualifier = ClassQualifier.new(class_qualifier.to_s)

  raise ArgumentError, "invalid id: #{id.inspect}"               if @id.empty?
  raise ArgumentError, "invalid treatment: #{treatment.inspect}" unless TREATMENTS.include?(@treatment)

  freeze
end

Instance Attribute Details

#class_qualifierClassQualifier (readonly)



20
21
22
# File 'lib/sidekiq/antidote/inhibitor.rb', line 20

def class_qualifier
  @class_qualifier
end

#idString (readonly)



14
15
16
# File 'lib/sidekiq/antidote/inhibitor.rb', line 14

def id
  @id
end

#treatment"skip", "kill" (readonly)



17
18
19
# File 'lib/sidekiq/antidote/inhibitor.rb', line 17

def treatment
  @treatment
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==



44
45
46
47
# File 'lib/sidekiq/antidote/inhibitor.rb', line 44

def eql?(other)
  self.class == other.class \
    && id == other.id && treatment == other.treatment && class_qualifier == other.class_qualifier
end

#match?(job_record) ⇒ Boolean



36
37
38
# File 'lib/sidekiq/antidote/inhibitor.rb', line 36

def match?(job_record)
  class_qualifier.match?(job_record.display_class)
end

#to_sObject



40
41
42
# File 'lib/sidekiq/antidote/inhibitor.rb', line 40

def to_s
  "#{treatment} #{class_qualifier}"
end