lib/jcukeforker/task_manager.rb in jcukeforker-0.2.9 vs lib/jcukeforker/task_manager.rb in jcukeforker-0.2.10
- old
+ new
@@ -5,10 +5,11 @@
def initialize(features, opts={})
@features = features
@opts = opts
@worker_sockets = {}
@failures = false
+ @mutex = Mutex.new
end
def on_worker_register(worker_path)
@worker_sockets[worker_path] = UNIXSocket.open worker_path
pop_task worker_path
@@ -33,13 +34,15 @@
end
private
def pop_task(worker_path)
- task = '__KILL__'
- if feature = @features.shift
- task = @opts.merge(feature: feature).to_json
- end
+ task = '__KILL__'
+ @mutex.synchronize do
+ if feature = @features.shift
+ task = @opts.merge(feature: feature).to_json
+ end
+ end
@worker_sockets[worker_path].puts(task)
end
end
end