monitor: tweak/simplify Progress
Tweak the Progress class to be simpler. Given that progress does not need to support arbitrary depth but only has a single level the class now just exposes "sub_progress" to the caller. When the main progress is advanced the sub_progress is now fully deleted instead of just reset. The rational is that when the main progress is done and advances a step it is very likely that a new sub_progress is required and it's most likely an error if the same sub_progress will get re-used. This means that `reset()` can be removed as it's not used anymore (and YAGNI). We can add it back when we have a use-case. It also change the code so that "total" starts with 0 instead of `None` (principle of least surprise). This means that now `progress.incr()` is called in the JSONSeqMonitor() for `finish()` and `result()` to indicate that the pipeline/stage is finished.
This commit is contained in:
parent
de9ead53a2
commit
3fbd0b2a73
2 changed files with 42 additions and 36 deletions
|
|
@ -160,25 +160,27 @@ def test_context():
|
|||
|
||||
def test_progress():
|
||||
prog = Progress("test", total=12)
|
||||
subprog = Progress("test-sub1", total=3)
|
||||
prog.sub_progress(subprog)
|
||||
assert prog.done is None # starts with None until the first incr()
|
||||
prog.incr()
|
||||
|
||||
prog.incr(depth=1)
|
||||
prog.sub_progress = Progress("test-sub1", total=3)
|
||||
# we start empty
|
||||
progdict = prog.as_dict()
|
||||
assert progdict["done"] == 0
|
||||
assert progdict["progress"]["done"] == 0
|
||||
|
||||
prog.incr(depth=1)
|
||||
# incr a sub_progress only affect sub_progress
|
||||
prog.sub_progress.incr()
|
||||
progdict = prog.as_dict()
|
||||
assert progdict["done"] == 0
|
||||
assert progdict["progress"]["done"] == 1
|
||||
|
||||
prog.sub_progress.incr()
|
||||
progdict = prog.as_dict()
|
||||
assert progdict["done"] == 0
|
||||
assert progdict["progress"]["done"] == 2
|
||||
|
||||
prog.incr()
|
||||
progdict = prog.as_dict()
|
||||
assert progdict["done"] == 1
|
||||
assert progdict["progress"]["done"] is None, "sub-progress did not reset"
|
||||
assert progdict.get("progress") == None, "sub-progress did not reset"
|
||||
|
||||
|
||||
def test_json_progress_monitor():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue