示例#1
0
def execute_interface_test(interface_test_id=None):
    if interface_test_id == None:
        return {'error': '无效的请求'}, 404

    db = get_db()
    logger = get_logger()
    user_id = session.get('user_id')
    user_obj = db.query(Userinfo).filter(Userinfo.id == user_id).first()
    logger.debug("执行内容:%s, 执行的用户id:%s, 执行的接口测试id:%s" %
                 ('interface_test', user_obj.id, interface_test_id))

    data = {
        'opt': 'execute_interface_test',
        'data': {
            'interface_test_id': interface_test_id,
            'user_id': session.get('user_id')
        }
    }

    ret = send_to_redis(data)
    if ret != 1:
        logger.warning('像redis添加数据失败.')
        return {'error': '执行失败! 请稍后重试.'}, 500

    # try:
    #     send_to_selenium(data)
    # except ConnectionResetError as error:
    #     # 让其重新连接,但不再发数据
    #     send_to_selenium({}, conn_flag=True)
    #     # 告诉前端这次请求失败
    #     logger.warning('连接selenium失败. %s' % error)
    #     return {'error': '执行失败! 请稍后重试.'}, 500

    return {}, 202
示例#2
0
    mongodb_host,
    mongodb_port,
    mongodb_database,
    mongodb_job_table,
    redis_host,
    redis_port,
    redis_db,
    redis_password
)
from lib.global_func import (
    send_content,
    get_logger,
    send_to_redis
)

logger = get_logger()


class MyScheduler(object):

    __flag = None

    # 单例模式
    def __new__(cls, *args, **kwargs):
        if not cls.__flag:
            cls.__flag = super().__new__(cls)
        return cls.__flag

    def __init__(self):
        if 'scheduler' not in self.__dict__:
            # MongoDB的客户端连接配置