def start(self): try: AbstractInstance.start(self) finally: ji = self.job_instance if not Status.is_failure(self.status): for sub_dep in self.node.sub_deps.all(): sub_node = sub_dep.child ni = sub_node.nis.get(job_instance=ji) if ni.can_run(): self.job_instance.schedule.queue.push(ni)
def run(self, instance): """Enqueue instances for all nodes that don't have dependencies.""" for node in self.nodes.all(): node_instance = JobNodeInstance.objects.create( node=node, job_instance=instance) if node_instance.can_run(): instance.schedule.queue.push(node_instance) while True: complete = True for ni in instance.nodis.all(): if not Status.is_final(ni.status): complete = False elif Status.is_failure(ni.status): return False if complete and instance.nodis.count() == self.nodes.count(): return True time.sleep(1)