Class: Sidekiq::Throttled::Strategy
- Inherits:
-
Object
- Object
- Sidekiq::Throttled::Strategy
- Defined in:
- lib/sidekiq/throttled/strategy.rb,
lib/sidekiq/throttled/strategy/script.rb,
lib/sidekiq/throttled/strategy/threshold.rb,
lib/sidekiq/throttled/strategy/concurrency.rb
Overview
Meta-strategy that couples Concurrency and Threshold strategies.
Defined Under Namespace
Classes: Concurrency, Threshold
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #dynamic_keys? ⇒ Boolean
-
#finalize!(jid, *job_args) ⇒ void
Marks job as being processed.
-
#initialize(name, concurrency: nil, threshold: nil, key_suffix: nil) ⇒ Strategy
constructor
A new instance of Strategy.
-
#reset! ⇒ void
Resets count of jobs of all avaliable strategies.
-
#throttled?(jid, *job_args) ⇒ Boolean
Whenever job is throttled or not.
Constructor Details
#initialize(name, concurrency: nil, threshold: nil, key_suffix: nil) ⇒ Strategy
Returns a new instance of Strategy.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sidekiq/throttled/strategy.rb', line 25 def initialize(name, concurrency: nil, threshold: nil, key_suffix: nil) key = "throttled:#{name}" if concurrency @concurrency = Concurrency.new( key, concurrency.merge(:key_suffix => key_suffix) ) end if threshold @threshold = Threshold.new( key, threshold.merge(:key_suffix => key_suffix) ) end return if @concurrency || @threshold raise ArgumentError, "Neither :concurrency nor :threshold given" end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
13 14 15 |
# File 'lib/sidekiq/throttled/strategy.rb', line 13 def concurrency @concurrency end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
17 18 19 |
# File 'lib/sidekiq/throttled/strategy.rb', line 17 def threshold @threshold end |
Instance Method Details
#dynamic_keys? ⇒ Boolean
44 45 46 47 |
# File 'lib/sidekiq/throttled/strategy.rb', line 44 def dynamic_keys? (@concurrency && @concurrency.dynamic_keys?) || (@threshold && @threshold.dynamic_keys?) end |
#finalize!(jid, *job_args) ⇒ void
This method returns an undefined value.
Marks job as being processed.
63 64 65 |
# File 'lib/sidekiq/throttled/strategy.rb', line 63 def finalize!(jid, *job_args) @concurrency && @concurrency.finalize!(jid, *job_args) end |
#reset! ⇒ void
This method returns an undefined value.
Resets count of jobs of all avaliable strategies
69 70 71 72 |
# File 'lib/sidekiq/throttled/strategy.rb', line 69 def reset! @concurrency && @concurrency.reset! @threshold && @threshold.reset! end |
#throttled?(jid, *job_args) ⇒ Boolean
Returns whenever job is throttled or not.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sidekiq/throttled/strategy.rb', line 50 def throttled?(jid, *job_args) return true if @concurrency && @concurrency.throttled?(jid, *job_args) if @threshold && @threshold.throttled?(*job_args) finalize!(jid, *job_args) return true end false end |