コード例 #1
0
def on_exec_test(data):
    try:
        data['testCaseSuiteIdList'] = data['testCaseSuiteIdList'].strip(
        ).split(';')
    except BaseException:
        raise TypeError('参数 「testCaseSuiteIdList」 不合法')

    try:
        data['testDomain'] = data['testDomain'].strip()
    except BaseException:
        raise TypeError('参数 「testDomain」 不合法')

    data['isExecuteForbiddenedCase'] = True if data.get('isExecuteForbiddenedCase') \
                                               and common.can_convert_to_str(data.get('isExecuteForbiddenedCase'))\
                                               and data.get('isExecuteForbiddenedCase').upper() == 'TRUE' else False

    data['isDingDingNotify'] = True if data.get('isDingDingNotify')\
                                            and common.can_convert_to_str(data.get('isDingDingNotify'))\
                                            and data.get('isDingDingNotify').upper() == 'TRUE' else False

    data['isEnterpriseWechatNotify'] = True if data.get('isEnterpriseWechatNotify')\
                                       and common.can_convert_to_str(data.get('isEnterpriseWechatNotify')) \
                                       and data.get('isEnterpriseWechatNotify').upper() == 'TRUE' else False

    data['dingdingAccessToken'] = data.get('dingdingAccessToken').strip() if data.get('dingdingAccessToken')\
                                        and common.can_convert_to_str(data.get('dingdingAccessToken')) else None

    data['enterpriseWechatAccessToken'] = data.get('enterpriseWechatAccessToken').strip()\
        if data.get('enterpriseWechatAccessToken') and common.can_convert_to_str(data.get('enterpriseWechatAccessToken')) else None

    try:
        data['alarmMailList'] = data['alarmMailList'].strip().split(
            ';') if data.get('alarmMailList') else []
    except BaseException:
        raise TypeError('参数 「alarmMailList」 不合法')

    data["testCaseIdList"] = []
    data['triggerType'] = "date"
    data['runDate'] = datetime.datetime.now()  # 瞬间触发
    filtered_data = CronTab.filter_field(data, use_set_default=True)
    cron = Cron(
        test_case_suite_id_list=filtered_data.get('testCaseSuiteIdList'),
        test_domain=filtered_data.get('testDomain'),
        alarm_mail_list=filtered_data.get('alarmMailList'),
        trigger_type=filtered_data.get('triggerType'),
        test_case_id_list=filtered_data.get('testCaseIdList'),
        is_execute_forbiddened_case=filtered_data.get(
            'isExecuteForbiddenedCase'),
        run_date=filtered_data.get('runDate'),
        is_ding_ding_notify=filtered_data.get('isDingDingNotify'),
        ding_ding_access_token=filtered_data.get('dingdingAccessToken'),
        is_enterprise_wechat_notify=filtered_data.get(
            'isEnterpriseWechatNotify'),
        enterprise_wechat_access_token=filtered_data.get(
            'enterpriseWechatAccessToken'),
        is_web_hook=True)
    cron_manager.add_cron(cron)
コード例 #2
0
ファイル: cronTab.py プロジェクト: zhangjiya/Taisite-Platform
def add_cron(project_id):
    try:
        request.get_json()["projectId"] = ObjectId(project_id)
        request.get_json()["createAt"] = datetime.datetime.utcnow()
        request.get_json()["lastUpdateTime"] = datetime.datetime.utcnow()
        data = request.get_json()

        if 'interval' in data:
            data['interval'] = float(data['interval'])

        if 'interval' in data and data['interval'] < 60:
            return jsonify({'status': 'failed', 'data': '定时任务间隔不可小于60秒!'})

        if 'runDate' in data:
            data['runDate'] = common.frontend_date_str2datetime(data['runDate'])

        filtered_data = CronTab.filter_field(data, use_set_default=True)
        if filtered_data.get('runDate'):
            cron = Cron(test_case_suite_id_list=filtered_data.get('testCaseSuiteIdList'),
                        test_domain=filtered_data.get('testDomain'),
                        alarm_mail_list=filtered_data.get('alarmMailList'),
                        is_ding_ding_notify=filtered_data.get('isDingDingNotify'),
                        ding_ding_access_token=filtered_data.get('dingdingAccessToken'),
                        ding_ding_notify_strategy=filtered_data.get('dingdingNotifyStrategy'),
                        is_enterprise_wechat_notify=filtered_data.get('isEnterpriseWechatNotify'),
                        enterprise_wechat_access_token=filtered_data.get('enterpriseWechatAccessToken'),
                        enterprise_wechat_notify_strategy=filtered_data.get('enterpriseWechatNotifyStrategy'),
                        trigger_type=filtered_data.get('triggerType'),
                        test_case_id_list=filtered_data.get('testCaseIdList'),
                        is_execute_forbiddened_case=filtered_data.get('isExecuteForbiddenedCase'),
                        run_date=filtered_data.get('runDate'))
        else:
            cron = Cron(test_case_suite_id_list=filtered_data.get('testCaseSuiteIdList'),
                        test_domain=filtered_data.get('testDomain'),
                        alarm_mail_list=filtered_data.get('alarmMailList'),
                        is_ding_ding_notify=filtered_data.get('isDingDingNotify'),
                        ding_ding_access_token=filtered_data.get('dingdingAccessToken'),
                        ding_ding_notify_strategy=filtered_data.get('dingdingNotifyStrategy'),
                        is_enterprise_wechat_notify=filtered_data.get('isEnterpriseWechatNotify'),
                        enterprise_wechat_access_token=filtered_data.get('enterpriseWechatAccessToken'),
                        enterprise_wechat_notify_strategy=filtered_data.get('enterpriseWechatNotifyStrategy'),
                        trigger_type=filtered_data.get('triggerType'),
                        test_case_id_list=filtered_data.get('testCaseIdList'),
                        is_execute_forbiddened_case=filtered_data.get('isExecuteForbiddenedCase'),
                        seconds=filtered_data.get('interval'))
        cron_id = cron_manager.add_cron(cron)
        for key, value in filtered_data.items():

            CronTab.update({"_id": cron_id},
                           {'$set': {key: value}})
        update_response = CronTab.update({"_id": cron_id},
                                         {'$set': {'lastUpdateTime': datetime.datetime.utcnow()}})
        if update_response["n"] == 0:
            return jsonify({'status': 'failed', 'data': '新建成功但未找到相应更新数据!'})
        return jsonify({'status': 'ok', 'data': '新建成功'})
    except BaseException as e:
        return jsonify({'status': 'failed', 'data': '新建失败: %s' % e})
コード例 #3
0
ファイル: cron_job.py プロジェクト: tanshinepan/leo-api-auto
def add_cron_job(project_id):
    try:
        request_data = request.get_json()
        request_data["projectId"] = ObjectId(project_id)
        request_data["testEnvId"] = ObjectId(request_data["testEnvId"])
        if request_data["alarmMailGroupList"] and len(
                request_data["alarmMailGroupList"]) > 0:
            for index, value in enumerate(request_data["alarmMailGroupList"]):
                request_data["alarmMailGroupList"][index] = ObjectId(value)
        request_data["createAt"] = datetime.utcnow()
        if 'interval' in request_data and request_data['interval'] < 60:
            return jsonify({'status': 'failed', 'data': '定时任务间隔不可小于60秒!'})

        if 'interval' in request_data:
            request_data['interval'] = float(request_data['interval'])

        if 'runDate' in request_data:
            request_data['runDate'] = common.frontend_date_str2datetime(
                request_data['runDate'])
        filtered_data = CronJob.filter_field(request_data,
                                             use_set_default=True)
        if filtered_data.get('runDate'):
            cron = Cron(
                test_suite_id_list=filtered_data.get('testSuiteIdList'),
                project_id=project_id,
                test_env_id=filtered_data.get('testEnvId'),
                trigger_type=filtered_data.get('triggerType'),
                include_forbidden=filtered_data.get('includeForbidden'),
                alarm_mail_group_list=filtered_data.get('alarmMailGroupList'),
                run_date=filtered_data.get('runDate'))
        else:
            cron = Cron(
                test_suite_id_list=filtered_data.get('testSuiteIdList'),
                project_id=project_id,
                test_env_id=filtered_data.get('testEnvId'),
                trigger_type=filtered_data.get('triggerType'),
                include_forbidden=filtered_data.get('includeForbidden'),
                alarm_mail_group_list=filtered_data.get('alarmMailGroupList'),
                seconds=filtered_data.get('interval'))
        cron_id = cron_manager.add_cron(cron)
        filtered_data['lastUpdateTime'] = datetime.utcnow()
        update_response = CronJob.update({"_id": cron_id},
                                         {'$set': filtered_data})
        if update_response["n"] == 0:
            return jsonify({'status': 'failed', 'data': '新建成功但未找到相应更新数据!'})
        current_app.logger.info("add cron job successfully. New Cron Id: %s" %
                                str(cron_id))
        return jsonify({'status': 'ok', 'data': '新建成功'})
    except BaseException as e:
        current_app.logger.error("add cron job failed. - %s" % str(e))
        return jsonify({'status': 'failed', 'data': '新建失败: %s' % e})
コード例 #4
0
def add_cron_job(project_id):
    try:
        request_data = request.get_json()
        request_data["projectId"] = ObjectId(project_id)
        request_data["testEnvId"] = ObjectId(request_data["testEnvId"])
        if "alarmMailGroupList" in request_data and len(
                request_data["alarmMailGroupList"]) > 0:
            for index, value in enumerate(request_data["alarmMailGroupList"]):
                request_data["alarmMailGroupList"][index] = ObjectId(value)
        request_data["createAt"] = datetime.utcnow()
        if 'interval' in request_data and request_data['interval'] < 60:
            return jsonify({'status': 'failed', 'data': '定时任务间隔不可小于60秒!'})

        if 'interval' in request_data:
            request_data['interval'] = float(request_data['interval'])

        if 'runDate' in request_data:
            request_data['runDate'] = common.frontend_date_str2datetime(
                request_data['runDate'])
        filtered_data = CronJob.filter_field(request_data,
                                             use_set_default=True)
        new_cron_job_id = str(common.get_object_id())
        if filtered_data.get('runDate'):
            cron = Cron(
                cron_job_id=new_cron_job_id,
                test_suite_id_list=filtered_data.get('testSuiteIdList'),
                project_id=project_id,
                test_env_id=filtered_data.get('testEnvId'),
                trigger_type=filtered_data.get('triggerType'),
                include_forbidden=filtered_data.get('includeForbidden'),
                enable_wxwork_notify=filtered_data.get('enableWXWorkNotify'),
                wxwork_api_key=filtered_data.get('WXWorkAPIKey'),
                wxwork_mention_mobile_list=filtered_data.get(
                    'WXWorkMentionMobileList'),
                always_wxwork_notify=filtered_data.get('alwaysWXWorkNotify'),
                enable_ding_talk_notify=filtered_data.get(
                    'enableDingTalkNotify'),
                ding_talk_access_token=filtered_data.get(
                    'DingTalkAccessToken'),
                ding_talk_at_mobiles=filtered_data.get('DingTalkAtMobiles'),
                ding_talk_secret=filtered_data.get('DingTalkSecret'),
                always_ding_talk_notify=filtered_data.get(
                    'alwaysDingTalkNotify'),
                alarm_mail_group_list=filtered_data.get('alarmMailGroupList'),
                always_send_mail=filtered_data.get('alwaysSendMail'),
                run_date=filtered_data.get('runDate'))
        else:
            cron = Cron(
                cron_job_id=new_cron_job_id,
                test_suite_id_list=filtered_data.get('testSuiteIdList'),
                project_id=project_id,
                test_env_id=filtered_data.get('testEnvId'),
                trigger_type=filtered_data.get('triggerType'),
                include_forbidden=filtered_data.get('includeForbidden'),
                enable_wxwork_notify=filtered_data.get('enableWXWorkNotify'),
                wxwork_api_key=filtered_data.get('WXWorkAPIKey'),
                wxwork_mention_mobile_list=filtered_data.get(
                    'WXWorkMentionMobileList'),
                always_wxwork_notify=filtered_data.get('alwaysWXWorkNotify'),
                enable_ding_talk_notify=filtered_data.get(
                    'enableDingTalkNotify'),
                ding_talk_access_token=filtered_data.get(
                    'DingTalkAccessToken'),
                ding_talk_at_mobiles=filtered_data.get('DingTalkAtMobiles'),
                ding_talk_secret=filtered_data.get('DingTalkSecret'),
                always_ding_talk_notify=filtered_data.get(
                    'alwaysDingTalkNotify'),
                alarm_mail_group_list=filtered_data.get('alarmMailGroupList'),
                always_send_mail=filtered_data.get('alwaysSendMail'),
                seconds=filtered_data.get('interval'))
        cron_id = cron_manager.add_cron(cron)
        filtered_data['lastUpdateTime'] = datetime.utcnow()
        update_response = CronJob.update({"_id": cron_id},
                                         {'$set': filtered_data})
        if update_response["n"] == 0:
            return jsonify({'status': 'failed', 'data': '新建成功但未找到相应更新数据!'})
        current_app.logger.info("add cron job successfully. New Cron Id: %s" %
                                str(cron_id))
        return jsonify({'status': 'ok', 'data': '新建成功'})
    except BaseException as e:
        current_app.logger.error("add cron job failed. - %s" % str(e))
        return jsonify({'status': 'failed', 'data': '新建失败: %s' % e})