Sha256: c48925e6b14e1b4c4b2157a416de2c262e39246cf12bfc101f0539ec35379837

Contents?: true

Size: 931 Bytes

Versions: 4

Compression:

Stored size: 931 Bytes

Contents

module JCukeForker
  class TaskManager < AbstractListener

    def initialize(features, opts={})
      @features = features
      @opts = opts
      @worker_sockets = {}
      @failures = false
    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)
      @failures = @failures || !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

    def has_failures?
      @failures
    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

4 entries across 4 versions & 1 rubygems

Version Path
jcukeforker-0.2.9 lib/jcukeforker/task_manager.rb
jcukeforker-0.2.8 lib/jcukeforker/task_manager.rb
jcukeforker-0.2.7 lib/jcukeforker/task_manager.rb
jcukeforker-0.2.6 lib/jcukeforker/task_manager.rb