Class: Procrastinate::SpawnStrategy::Throttled

Inherits:
Simple
  • Object
show all
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

Default

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#currentObject (readonly)

Returns the value of attribute current.



6
7
8
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 6

def current
  @current
end

#limitObject (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_deadObject



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_spawnObject



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

Returns:

  • (Boolean)


16
17
18
# File 'lib/procrastinate/spawn_strategy/throttled.rb', line 16

def should_spawn?
  current < limit
end