Class: Chore::Strategy::WorkDistributor

Inherits:
Object
  • Object
show all
Extended by:
Ipc
Defined in:
lib/chore/strategies/worker/helpers/work_distributor.rb

Overview

:nodoc:

Constant Summary

Constants included from Ipc

Ipc::BIG_ENDIAN, Ipc::MSG_BYTES, Ipc::READY_MSG

Class Method Summary collapse

Methods included from Ipc

add_worker_socket, child_connection, clear_ready, create_master_socket, delete_socket_file, ipc_help, read_msg, select_sockets, send_msg, signal_ready

Class Method Details

.fetch_and_assign_jobs(workers, manager) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chore/strategies/worker/helpers/work_distributor.rb', line 9

def fetch_and_assign_jobs(workers, manager)
  jobs = manager.fetch_work(workers.size)
  raise "DW: jobs needs to be a list got #{jobs.class}" unless jobs.is_a?(Array)
  if jobs.empty?
    # This conditon is due to the internal consumer queue being empty.
    # Assuming that the the consumer has to fetch from an external queue,
    # if we return here, we would create a tight loop that would use up
    # a lot the CPU's time. In order to prevent that, we wait for the
    # consumer queue to be populated, by sleeping. 
    sleep(0.1)
    return
  end
  jobs_to_return = assign_jobs(jobs, workers)
  manager.return_work(jobs_to_return)
end