Example #1
0
    def restart(self, user: User, idx: int) -> None:
        from piper_core.model.jobs.job import Job
        from piper_core.model.stages.stage import Stage

        try:
            build: Build = Build.get(Build.id == idx)
        except DoesNotExist:
            raise FacadeNotFound

        if user.role is not UserRole.MASTER:
            try:
                ProjectUser.get((ProjectUser.user == user)
                                & (ProjectUser.project == build.project))
            except DoesNotExist:
                raise FacadeUnauthorized

        if build.status not in Status.final_statuses():
            raise FacadeInvalidAction

        build.restart()
        first = Stage.select().where(Stage.build == build).order_by(
            Stage.order.asc()).first()
        jobs = Job.select().where(Job.stage == first)
        for job in jobs:
            job.status = Status.READY
            job.save()
            self.queue.push(job)
Example #2
0
    def cancel(self, user: User, idx: int) -> None:
        from piper_core.model.jobs.job import Job
        try:
            stage: Stage = Stage.get(Stage.id == idx)
        except DoesNotExist:
            raise FacadeNotFound

        if user.role is not UserRole.MASTER:
            try:
                ProjectUser.get((ProjectUser.user == user)
                                & (ProjectUser.project == stage.build.project))
            except DoesNotExist:
                raise FacadeUnauthorized

        if stage.status not in Status.cancelable_statuses():
            raise FacadeInvalidAction

        stage.cancel()
        next_stage: Stage = Stage.get((Stage.build == stage.build)
                                      & (Stage.order == stage.order + 1))
        if not next_stage or next_stage.status is not Status.READY:
            return

        jobs = Job.select().where(Job.stage == next_stage)
        for job in jobs:
            self.queue.push(job)
Example #3
0
    def parse_webhook(self, data):
        from piper_core.model.stages.stage import Stage
        from piper_core.model.jobs.job import Job
        from piper_core.model.jobs.environment import Environment

        commit = self.github.parse_webhook(data)
        yml = self.github.fetch_piper_yml(commit)

        project = Project.get(
            Project.origin == commit.branch.repository.origin)
        build = Build(project=project,
                      branch=commit.branch.name,
                      commit=commit.sha)
        self.create_build(yml, build)

        jobs = Job.select().join(Stage).where(Stage.build == build)
        for job in jobs:
            Environment.create(name='PIPER', value=True, job=job)
            Environment.create(name='PIPER_BRANCH',
                               value=commit.branch.name,
                               job=job)
            Environment.create(name='PIPER_COMMIT', value=commit.sha, job=job)
            Environment.create(name='PIPER_COMMIT_MESSAGE',
                               value=commit.message,
                               job=job)
            Environment.create(name='PIPER_JOB_ID', value=job.id, job=job)
            Environment.create(name='PIPER_BUILD_ID', value=build.id, job=job)
            Environment.create(name='PIPER_STAGE',
                               value=job.stage.name,
                               job=job)

        first = Stage.select().where(Stage.build == build).order_by(
            Stage.order.asc()).first()

        jobs = Job.select().where(Job.stage == first)
        for job in jobs:
            job.status = Status.READY
            job.save()
            self.queue.push(job)
Example #4
0
    def cancel(self):
        from piper_core.model.jobs.job import Job

        with database_proxy.transaction():
            jobs = Job.select().where((Job.stage == self) & (
                Job.status.in_(Status.cancelable_statuses())))
            for job in jobs:
                job.status = Status.CANCELED
                job.save()

            self.status = Stage.get(Stage.id == self.id).status
            self._set_build_status()
            self.build.save()
Example #5
0
    def restart(self):
        from piper_core.model.jobs.job import Job

        with database_proxy.transaction():
            jobs = Job.select().where((Job.stage == self) & (
                Job.status.in_(Status.final_statuses())))

            for job in jobs:
                job.status = Status.READY
                job.secret = uuid.uuid4().hex
                job.save()

            self.status = Stage.get(Stage.id == self.id).status
            self._set_build_status()
            self.build.save()
Example #6
0
    def restart(self, user: User, idx: int) -> None:
        from piper_core.model.jobs.job import Job

        try:
            stage = Stage.get(Stage.id == idx)
        except DoesNotExist:
            raise FacadeNotFound

        if user.role is not UserRole.MASTER:
            try:
                ProjectUser.get((ProjectUser.user == user)
                                & (ProjectUser.project == stage.build.project))
            except DoesNotExist:
                raise FacadeUnauthorized

        if stage.status not in Status.final_statuses():
            raise FacadeInvalidAction

        stage.restart()
        jobs: List[Job] = Job.select().where((Job.stage == stage)
                                             & (Job.status == Status.READY))

        for job in jobs:
            self.queue.push(job)