lib/cukeforker/worker_queue.rb in cukeforker-0.0.2 vs lib/cukeforker/worker_queue.rb in cukeforker-0.0.3

- old
+ new

@@ -68,10 +68,32 @@ def has_failures? @finished.any? { |w| w.failed? } end + def eta + pending = @pending.size + finished = @finished.size + running = @running.size + + remaining = pending + running + + if finished == 0 + result = [Time.now, remaining, finished] + fire :on_eta, *result + else + seconds_per_child = (Time.now - start_time) / finished.to_f + eta = Time.now + (seconds_per_child * remaining) + + result = [eta, remaining, finished] + + fire :on_eta, *result + end + + result + end + private def start(worker) fire :on_worker_starting, worker @@ -82,21 +104,9 @@ def finish(worker) @running.delete worker @finished << worker fire :on_worker_finished, worker - end - - def eta - return Time.now if @finished.empty? - - pending = @pending.size - finished = @finished.size - - seconds_per_child = (Time.now - start_time) / finished - eta = Time.now + (seconds_per_child * pending) - - fire :on_eta, eta, pending + size, finished end def fire(*args) changed notify_observers(*args)