Ejemplo n.º 1
0
    def end(self, success=True, update_status=True):
        if update_status:
            status = TaskModel.status_success if success else TaskModel.status_fail
            current_app.logger.info('success:%s, status:%s' %
                                    (success, status))
            TaskModel().get_by_id(self.task_id).update({
                'status':
                status,
                'link_id':
                self.release_version,
                'ex_link_id':
                self.previous_release_version,
            })

            notice_info = {
                'title':
                '',
                'username':
                current_user.username,
                'project_name':
                self.project_info['name'],
                'task_name':
                '%s ([%s](%s))' %
                (self.taskMdl.get('name'), self.task_id,
                 Notice.task_url(project_name=self.project_info['name'],
                                 task_id=self.task_id)),
                'branch':
                self.taskMdl.get('branch'),
                'commit':
                self.taskMdl.get('commit_id'),
                'is_branch':
                self.project_info['repo_mode'],
            }
            notice = Notice.create(self.project_info['notice_type'])
            if success:
                notice_info['title'] = '上线部署成功'
                notice.deploy_task(project_info=self.project_info,
                                   notice_info=notice_info)
            else:
                notice_info['title'] = '上线部署失败'
                notice.deploy_task(project_info=self.project_info,
                                   notice_info=notice_info)

        if success:
            emit('success', {
                'event': 'finish',
                'data': {
                    'message': '部署完成,辛苦了,为你的努力喝彩!'
                }
            },
                 room=self.task_id)
        else:
            emit('fail', {
                'event': 'finish',
                'data': {
                    'message': Code.code_msg[Code.deploy_fail]
                }
            },
                 room=self.task_id)
Ejemplo n.º 2
0
    def end(self, success=True, update_status=True):
        if update_status:
            status = TaskModel.status_success if success else TaskModel.status_fail
            current_app.logger.info('success:%s, status:%s' % (success, status))
            TaskModel().get_by_id(self.task_id).update({
                'status': status,
                'link_id': self.release_version,
                'ex_link_id': self.previous_release_version,
            })

            notice_info = {
                'title': '',
                'username': current_user.username,
                'project_name': self.project_info['name'],
                'task_name': '%s ([%s](%s))' % (self.taskMdl.get('name'), self.task_id, Notice.task_url(project_name=self.project_info['name'], task_id=self.task_id)),
                'branch': self.taskMdl.get('branch'),
                'commit': self.taskMdl.get('commit_id'),
                'is_branch': self.project_info['repo_mode'],
            }
            notice = Notice.create(self.project_info['notice_type'])
            if success:
                notice_info['title'] = '上线部署成功'
                notice.deploy_task(project_info=self.project_info, notice_info=notice_info)
            else:
                notice_info['title'] = '上线部署失败'
                notice.deploy_task(project_info=self.project_info, notice_info=notice_info)

        if success:
            emit('success', {'event': 'finish', 'data': {'message': '部署完成,辛苦了,为你的努力喝彩!'}}, room=self.task_id)
        else:
            emit('fail', {'event': 'finish', 'data': {'message': Code.code_msg[Code.deploy_fail]}}, room=self.task_id)
Ejemplo n.º 3
0
    def post(self):
        """
        create a task
        /task/
        :return:
        """
        super(TaskAPI, self).post()

        form = TaskForm(request.form, csrf=False)
        if form.validate_on_submit():
            task_new = TaskModel()
            data = form.form2dict()
            task_new_info = task_new.add(data)
            if not task_new_info:
                return self.render_json(code=-1)

            # 待审核
            try:
                if task_new_info['status'] == TaskModel.status_new:
                    project_info = ProjectModel(
                        id=task_new_info['project_id']).item()
                    space_id = project_info['space_id']
                    space_info = SpaceModel(id=space_id).item()
                    task_url = Notice.task_url(
                        project_space=space_info['name'],
                        task_id=task_new_info['id'])
                    notice_info = {
                        'title': '新上线单需要审核',
                        'username': current_user.username,
                        'project_name': project_info['name'],
                        'task_id': task_new_info['id'],
                        'task_url': task_url,
                        'task_name': task_new_info['name'],
                        'branch': task_new_info['branch'],
                        'commit': task_new_info['commit_id'],
                        'tag': task_new_info['tag'],
                        'repo_mode': project_info['repo_mode'],
                    }
                    Notice.create(Notice.by_dingding).audit_task(
                        project_info, notice_info)
            except:
                pass

            return self.render_json(data=task_new_info)
        else:
            return self.render_error(code=Code.form_error, message=form.errors)