lib/jcukeforker/task_manager.rb in jcukeforker-0.2.10 vs lib/jcukeforker/task_manager.rb in jcukeforker-0.3.1
- old
+ new
@@ -1,49 +1,40 @@
module JCukeForker
class TaskManager < AbstractListener
- def initialize(features, opts={})
+ def initialize(features, io_out, opts={})
@features = features
@opts = opts
- @worker_sockets = {}
+ @io_out = io_out
@failures = false
- @mutex = Mutex.new
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}
+ io_out.close
end
def has_failures?
@failures
end
private
def pop_task(worker_path)
- task = '__KILL__'
- @mutex.synchronize do
- if feature = @features.shift
- task = @opts.merge(feature: feature).to_json
- end
- end
+ task = {action: '__KILL__', worker: worker_path}.to_json
+ if feature = @features.shift
+ task = @opts.merge(worker: worker_path, feature: feature, action: :feature).to_json
+ end
- @worker_sockets[worker_path].puts(task)
+ @io_out.write("#{task}#{$-0}")
end
end
end