Class: Sidekiq::Congestion::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sidekiq/congestion/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, job, queue) ⇒ Request

Returns a new instance of Request.



13
14
15
16
17
18
# File 'lib/sidekiq/congestion/request.rb', line 13

def initialize(worker, job, queue)
  self.worker = worker
  self.args = job['args']
  opts = worker.sidekiq_options_hash || { }
  self.options = opts['congestion']
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



7
8
9
# File 'lib/sidekiq/congestion/request.rb', line 7

def args
  @args
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/sidekiq/congestion/request.rb', line 7

def options
  @options
end

#workerObject

Returns the value of attribute worker.



7
8
9
# File 'lib/sidekiq/congestion/request.rb', line 7

def worker
  @worker
end

Instance Method Details

#congestionObject



43
44
45
# File 'lib/sidekiq/congestion/request.rb', line 43

def congestion
  @congestion ||= ::Congestion.request key, options
end

#enabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/sidekiq/congestion/request.rb', line 20

def enabled?
  !!options && _enabled?
end

#keyObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/sidekiq/congestion/request.rb', line 32

def key
  @key ||= case options[:key]
  when Proc
    options[:key].call *args
  when String, Symbol
    options[:key].to_s
  else
    worker.class.name
  end
end

#reschedule!Object



28
29
30
# File 'lib/sidekiq/congestion/request.rb', line 28

def reschedule!
  worker.class.perform_in backoff, *args
end

#reschedule?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/sidekiq/congestion/request.rb', line 24

def reschedule?
  rejection_method == :reschedule
end