Sha256: 1e569fc1c736f61d287d2e9e2c3e07d4766c54d067dcb5d5a05ee9ead77f4457

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

module Kamerling class TaskDispatcher
  def initialize net_dispatcher: NetDispatcher, repos: Repos
    @net_dispatcher = net_dispatcher
    @repos          = repos
  end

  def dispatch
    repos.projects.each do |project|
      repos.free_clients_for(project).each do |client|
        task = repos.next_task_for(project)
        dispatch_task client: client, project: project, task: task if task
      end
    end
  end

  attr_reader :net_dispatcher, :repos
  private     :net_dispatcher, :repos

  private

  def dispatch_task client: req(:client), project: req(:project),
                    task: req(:task)
    message = Message[client: client, payload: task.data, project: project,
                      task: task, type: :DATA]
    net_dispatcher.dispatch client.addr, message.to_s
    client.busy = true
    repos << client
  end
end end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.2 lib/kamerling/task_dispatcher.rb