Class: Shoryuken::Manager

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/shoryuken/manager.rb

Constant Summary collapse

BATCH_LIMIT =
10
MIN_DISPATCH_INTERVAL =
0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#elapsed, #fire_event, #logger, #unparse_queues, #worker_name

Constructor Details

#initialize(group, fetcher, polling_strategy, concurrency, executor) ⇒ Manager

Returns a new instance of Manager.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shoryuken/manager.rb', line 13

def initialize(group, fetcher, polling_strategy, concurrency, executor)
  @group                      = group
  @fetcher                    = fetcher
  @polling_strategy           = polling_strategy
  @max_processors             = concurrency
  @busy_processors            = Shoryuken::Helpers::AtomicCounter.new(0)
  @executor                   = executor
  @running                    = Shoryuken::Helpers::AtomicBoolean.new(true)
  @stop_new_dispatching       = Shoryuken::Helpers::AtomicBoolean.new(false)
  @dispatching_release_signal = ::Queue.new
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



11
12
13
# File 'lib/shoryuken/manager.rb', line 11

def group
  @group
end

Instance Method Details

#await_dispatching_in_progressObject



34
35
36
37
38
39
# File 'lib/shoryuken/manager.rb', line 34

def await_dispatching_in_progress
  # There might still be a dispatching on-going, as the response from SQS could take some time
  # We don't want to stop the process before processing incoming messages, as they would stay "in-flight" for some time on SQS
  # We use a queue, as the dispatch_loop is running on another thread, and this is a efficient way of communicating between threads.
  @dispatching_release_signal.pop
end

#running?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/shoryuken/manager.rb', line 41

def running?
  @running.true? && @executor.running?
end

#startObject



25
26
27
28
# File 'lib/shoryuken/manager.rb', line 25

def start
  fire_utilization_update_event
  dispatch_loop
end

#stop_new_dispatchingObject



30
31
32
# File 'lib/shoryuken/manager.rb', line 30

def stop_new_dispatching
  @stop_new_dispatching.make_true
end