def make_cleanup(self): self.deployment.update_status(consts.DeployStatus.CLEANUP_STARTED) try: self.cleanup() except Exception: with excutils.save_and_reraise_exception(): self.deployment.update_status( consts.DeployStatus.CLEANUP_FAILED) else: self.deployment.update_status(consts.DeployStatus.CLEANUP_FINISHED)
def remove_path_on_error(path): """Protect code that wants to operate on PATH atomically. Any exception will cause PATH to be removed. :param path: File to work with """ try: yield except Exception: with excutils.save_and_reraise_exception(): delete_if_exists(path)
def make_deploy(self): self.deployment.update_status(consts.DeployStatus.DEPLOY_STARTED) try: endpoint = self.deploy() except Exception: with excutils.save_and_reraise_exception(): self.deployment.update_status( consts.DeployStatus.DEPLOY_FAILED) else: self.deployment.update_status(consts.DeployStatus.DEPLOY_FINISHED) return endpoint
def remove_path_on_error(path, remove=delete_if_exists): """Protect code that wants to operate on PATH atomically. Any exception will cause PATH to be removed. :param path: File to work with :param remove: Optional function to remove passed path """ try: yield except Exception: with excutils.save_and_reraise_exception(): remove(path)