예제 #1
0
파일: views.py 프로젝트: sajanv88/orchest
    def discoverFSDeletedProjects():
        """Cleanup projects that were deleted from the filesystem."""

        project_paths = [
            entry.name for entry in os.scandir(app.config["PROJECTS_DIR"])
            if entry.is_dir()
        ]

        fs_removed_projects = Project.query.filter(
            Project.path.notin_(project_paths),
            # This way we do not delete a project that is already being
            # deleted twice, and avoid considering a project that is
            # being initialized as deleted from the filesystem.
            Project.status.in_(["READY"]),
        ).all()

        # Use a TwoPhaseExecutor for each project so that issues in one
        # project do not hinder the deletion of others.
        for proj_uuid in [project.uuid for project in fs_removed_projects]:
            try:
                with TwoPhaseExecutor(db.session) as tpe:
                    DeleteProject(tpe).transaction(proj_uuid)
            except Exception as e:
                current_app.logger.error(
                    ("Error during project deletion (discovery) of "
                     f"{proj_uuid}: {e}."))
예제 #2
0
    def projects_delete():

        try:
            with TwoPhaseExecutor(db.session) as tpe:
                DeleteProject(tpe).transaction(request.json["project_uuid"])
        except Exception as e:
            return (
                jsonify({"message": f"Failed to delete the project. Error: {e}"}),
                500,
            )

        return jsonify({"message": "Project deleted."})