예제 #1
0
        def post(self):
            n_uuid = str(uuid.uuid4())
            new_task = BackgroundTask(task_uuid=n_uuid,
                                      task_type="GIT_CLONE_PROJECT",
                                      status="PENDING")
            db.session.add(new_task)
            db.session.commit()

            # start the background process in charge of cloning
            file_dir = os.path.dirname(os.path.realpath(__file__))
            args = [
                "python3",
                "-m",
                "scripts.background_tasks",
                "--type",
                "git_clone_project",
                "--uuid",
                n_uuid,
                "--url",
                request.json["url"],
            ]

            project_name = request.json.get("project_name", None)
            if project_name:
                args.append("--path")
                args.append(str(project_name))

            background_task_process = Popen(
                args,
                cwd=os.path.join(file_dir, "../.."),
                stderr=subprocess.STDOUT,
            )

            return background_task_schema.dump(new_task)
예제 #2
0
    def _transaction(self, url: str, project_name: Optional[str] = None):
        n_uuid = str(uuid.uuid4())
        new_task = BackgroundTask(uuid=n_uuid,
                                  task_type="GIT_CLONE_PROJECT",
                                  status="PENDING")
        db.session.add(new_task)

        # To be later used by the collateral function.
        self.collateral_kwargs["n_uuid"] = n_uuid
        self.collateral_kwargs["url"] = url
        self.collateral_kwargs["project_name"] = project_name
        return new_task