Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions plugins/callback/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,17 @@ def hms(seconds):

def eta(step, total, play_start, step_start, now):
"""The remaining time of a play, or None before the first step is done. The
time the finished steps took per step, times the steps left, less the time the
running step already took. It gets more accurate towards the end of the play.
time the finished steps took per step, times the steps after the running one,
plus what is left of that step's share. A step that runs longer than the
average, like an include_tasks with dozens of tasks, does not eat into the
estimate for the steps after it. It gets more accurate towards the end of the
play.
"""
done = step - 1
if done < 1:
return None
per_step = (step_start - play_start) / done
return max(per_step * (total - done) - (now - step_start), 0)
return per_step * (total - step) + max(per_step - (now - step_start), 0)


def progress_bar(step, total, width, color=True, remaining=None):
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/plugins/callback/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ def test_eta_from_the_finished_steps(self):
self.assertEqual(_module.eta(7, 21, 100, 160, 164), 146)
# no step done yet
self.assertIsNone(_module.eta(1, 21, 100, 100, 130))
# a step that takes longer than estimated does not go below zero
# a step that takes longer than the average, like a large include, keeps
# the estimate for the 14 steps after it
self.assertEqual(_module.eta(7, 21, 100, 160, 460), 140)
# and the last step does not go below zero
self.assertEqual(_module.eta(21, 21, 0, 200, 900), 0)


Expand Down
Loading