Class: Sidekiq::Throttled::Strategy::Concurrency
- Inherits:
-
Object
- Object
- Sidekiq::Throttled::Strategy::Concurrency
- Defined in:
- lib/sidekiq/throttled/strategy/concurrency.rb
Overview
Concurrency throttling strategy
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
-
#count ⇒ Integer
Current count of jobs.
-
#finalize!(jid) ⇒ void
Remove jid from the pool of jobs in progress.
-
#initialize(base_key, opts) ⇒ Concurrency
constructor
A new instance of Concurrency.
-
#reset! ⇒ void
Resets count of jobs.
-
#throttled?(jid) ⇒ Boolean
Whenever job is throttled or not.
Constructor Details
#initialize(base_key, opts) ⇒ Concurrency
Returns a new instance of Concurrency.
28 29 30 31 32 33 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 28 def initialize(base_key, opts) @key = "#{base_key}:concurrency".freeze @keys = [@key] @limit = opts.fetch(:limit).to_i @ttl = opts.fetch(:ttl, 900).to_i end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
21 22 23 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 21 def limit @limit end |
Instance Method Details
#count ⇒ Integer
Returns Current count of jobs.
41 42 43 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 41 def count Sidekiq.redis { |conn| conn.scard(@key) }.to_i end |
#finalize!(jid) ⇒ void
This method returns an undefined value.
Remove jid from the pool of jobs in progress
53 54 55 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 53 def finalize!(jid) Sidekiq.redis { |conn| conn.srem(@key, jid.to_s) } end |
#reset! ⇒ void
This method returns an undefined value.
Resets count of jobs
47 48 49 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 47 def reset! Sidekiq.redis { |conn| conn.del(@key) }.to_i end |
#throttled?(jid) ⇒ Boolean
Returns whenever job is throttled or not.
36 37 38 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 36 def throttled?(jid) 1 == SCRIPT.eval(@keys, [@limit, @ttl, jid.to_s]) end |