lib/jcukeforker/task_manager.rb in jcukeforker-0.2.4 vs lib/jcukeforker/task_manager.rb in jcukeforker-0.2.5
- old
+ new
@@ -1,18 +1,15 @@
module JCukeForker
class TaskManager < AbstractListener
- def initialize()
- @tasks = []
+ def initialize(features, opts={})
+ @features = features
+ @opts = opts
@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
@@ -30,11 +27,13 @@
end
private
def pop_task(worker_path)
- task = @tasks.shift || '__KILL__'
- task = task.to_json if task.is_a? Hash
+ task = '__KILL__'
+ if feature = @features.shift
+ task = @opts.merge(feature: feature).to_json
+ end
@worker_sockets[worker_path].puts(task)
end
end
end