pipeline: use deque to track stages to be built

Instead of iterating over the stages via indices, iterate over the
stages directly. To be able to do so, collect the stages that need
to be built in a deque and then drain it from the other end.
This commit is contained in:
Christian Kellner 2022-01-20 13:59:14 +00:00
parent d70a8d6419
commit 458e2063c9

View file

@ -300,12 +300,12 @@ class Pipeline:
# an intermediate checkpoint exists: Find the last stage that
# already exists in the store and use that as the base.
tree = object_store.new()
base_idx = -1
for i in reversed(range(len(self.stages))):
if object_store.contains(self.stages[i].id):
tree.base = self.stages[i].id
base_idx = i
todo = collections.deque()
for stage in reversed(self.stages):
if object_store.contains(stage.id):
tree.base = stage.id
break
todo.append(stage) # append right side of the deque
# If two run() calls race each-other, two trees will get built
# and it is nondeterministic which of them will end up
@ -314,7 +314,8 @@ class Pipeline:
# trees will be based on the winner.
results["stages"] = []
for stage in self.stages[base_idx + 1:]:
while todo:
stage = todo.pop()
with build_tree.read() as build_path, tree.write() as path:
monitor.stage(stage)