Sha256: 899565e938e3ede065e88a2c46e524c26322c43a3a978b44e95feae2d57d919b

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

module JCukeForker
  class TaskManager < AbstractListener

    def initialize(features, opts={})
      @features = features
      @opts = opts
      @worker_sockets = {}
    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 = '__KILL__'
      if feature = @features.shift
        task = @opts.merge(feature: feature).to_json
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jcukeforker-0.2.5 lib/jcukeforker/task_manager.rb