Class: Procrastinate::SpawnStrategy::Throttled
- Defined in:
- lib/procrastinate/spawn_strategy/throttled.rb
Overview
A dispatcher strategy that throttles tasks starting and ensures that no more than limit processes run concurrently.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
-
#initialize(limit) ⇒ Throttled
constructor
Client thread.
- #notify_dead ⇒ Object
- #notify_spawn ⇒ Object
- #should_spawn? ⇒ Boolean
Constructor Details
#initialize(limit) ⇒ Throttled
Client thread
9 10 11 12 13 14 |
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 9 def initialize(limit) super() @limit = limit @current = 0 end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
6 7 8 |
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 6 def current @current end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
6 7 8 |
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 6 def limit @limit end |
Instance Method Details
#notify_dead ⇒ Object
25 26 27 28 |
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 25 def notify_dead @current -= 1 warn "Throttled reports more deaths than births?!" if current < 0 end |
#notify_spawn ⇒ Object
20 21 22 23 |
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 20 def notify_spawn @current += 1 warn "Throttled reports too many births!" if current > limit end |
#should_spawn? ⇒ Boolean
16 17 18 |
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 16 def should_spawn? current < limit end |