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(*job_args) ⇒ Integer
Current count of jobs.
- #dynamic_keys? ⇒ Boolean
-
#finalize!(jid, *job_args) ⇒ void
Remove jid from the pool of jobs in progress.
-
#initialize(strategy_key, opts) ⇒ Concurrency
constructor
A new instance of Concurrency.
-
#reset!(*job_args) ⇒ void
Resets count of jobs.
-
#throttled?(jid, *job_args) ⇒ Boolean
Whenever job is throttled or not.
Constructor Details
#initialize(strategy_key, opts) ⇒ Concurrency
Returns a new instance of Concurrency.
31 32 33 34 35 36 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 31 def initialize(strategy_key, opts) @base_key = "#{strategy_key}:concurrency".freeze @limit = opts.fetch(:limit).to_i @ttl = opts.fetch(:ttl, 900).to_i @key_suffix = opts[:key_suffix] end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
22 23 24 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 22 def limit @limit end |
Instance Method Details
#count(*job_args) ⇒ Integer
Returns Current count of jobs.
48 49 50 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 48 def count(*job_args) Sidekiq.redis { |conn| conn.scard(key(job_args)) }.to_i end |
#dynamic_keys? ⇒ Boolean
38 39 40 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 38 def dynamic_keys? @key_suffix end |
#finalize!(jid, *job_args) ⇒ void
This method returns an undefined value.
Remove jid from the pool of jobs in progress
60 61 62 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 60 def finalize!(jid, *job_args) Sidekiq.redis { |conn| conn.srem(key(job_args), jid.to_s) } end |
#reset!(*job_args) ⇒ void
This method returns an undefined value.
Resets count of jobs
54 55 56 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 54 def reset!(*job_args) Sidekiq.redis { |conn| conn.del(key(job_args)) }.to_i end |
#throttled?(jid, *job_args) ⇒ Boolean
Returns whenever job is throttled or not.
43 44 45 |
# File 'lib/sidekiq/throttled/strategy/concurrency.rb', line 43 def throttled?(jid, *job_args) 1 == SCRIPT.eval([key(job_args)], [@limit, @ttl, jid.to_s]) end |