Class: CloudCrowd::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_crowd/dispatcher.rb

Overview

The dispatcher is responsible for distributing work_units to the worker nodes.

It automatically performs the distribution on a set schedule, but can also be signaled to perform distribution immediately

Instance Method Summary collapse

Constructor Details

#initialize(distribution_interval) ⇒ Dispatcher

Starts distributing jobs every “distribution_interval” seconds



11
12
13
14
15
# File 'lib/cloud_crowd/dispatcher.rb', line 11

def initialize(distribution_interval)
  @mutex  = Mutex.new
  @awaken = ConditionVariable.new
  distribute_periodically(distribution_interval)
end

Instance Method Details

#distribute!Object

Sends a signal to the distribution thread. If it’s asleep, it will wake up and perform a distribution.



19
20
21
22
23
# File 'lib/cloud_crowd/dispatcher.rb', line 19

def distribute!
  @mutex.synchronize do
    @awaken.signal
  end
end