Sha256: ed76e9d92420016370a3c81d54912ad349b8d6594945c90d0c671b213c4572b8

Contents?: true

Size: 868 Bytes

Versions: 2

Compression:

Stored size: 868 Bytes

Contents

module JCukeForker
  class TaskManager < AbstractListener

    def initialize()
      @tasks = []
      @worker_sockets = {}
    end

    def add(task)
      @tasks << task
    end

    def on_worker_register(worker_path)
      @worker_sockets[worker_path] = UNIXSocket.open worker_path
      pop_task worker_path
    end

    def on_task_finished(worker_path, feature, status)
      pop_task worker_path
    end

    def on_worker_dead(worker_path)
     socket = @worker_sockets.delete worker_path
     socket.close
    end

    def close
      @worker_sockets.each {|k, v| v.close}
    end

    private

    def pop_task(worker_path)
      task = @tasks.shift || '__KILL__'
      task = task.to_json if task.is_a? Hash

      if task.empty?
        puts "-----#{worker_path}...EMPTY TASK!"
      end

      @worker_sockets[worker_path].puts(task)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jcukeforker-0.2.3 lib/jcukeforker/task_manager.rb
jcukeforker-0.2.2 lib/jcukeforker/task_manager.rb