Exemplo n.º 1
0
    def create_post(loadpath=None,
                    sessionid=None,
                    hid=None,
                    custom_param=None):
        module_config = Xcache.get_moduleconfig(loadpath)
        # 获取模块配置
        if module_config is None:
            context = data_return(305, PostModuleActuator_MSG.get(305), {})
            return context

        # 处理模块参数
        try:
            custom_param = json.loads(custom_param)
        except Exception as E:
            logger.warning(E)
            custom_param = {}
        # 获取模块实例
        class_intent = importlib.import_module(loadpath)
        post_module_intent = class_intent.PostModule(sessionid, hid,
                                                     custom_param)

        # 模块前序检查,调用check函数
        try:
            flag, msg = post_module_intent.check()
            if flag is not True:
                # 如果检查未通过,返回未通过原因(msg)
                context = data_return(405, msg, {})
                return context
        except Exception as E:
            logger.warning(E)
            context = data_return(301, PostModuleActuator_MSG.get(301), {})
            return context

        try:
            broker = post_module_intent.MODULE_BROKER
        except Exception as E:
            logger.warning(E)
            context = data_return(305, PostModuleActuator_MSG.get(305), {})
            return context

        if broker == BROKER.post_python_job:
            # 放入多模块队列
            if aps_module.putin_post_python_module_queue(post_module_intent):
                context = data_return(201, PostModuleActuator_MSG.get(201), {})
                return context
            else:
                context = data_return(306, PostModuleActuator_MSG.get(306), {})
                return context
        elif broker == BROKER.post_msf_job:
            # 放入后台运行队列
            if MSFModule.putin_post_msf_module_queue(post_module_intent):
                context = data_return(201, PostModuleActuator_MSG.get(201), {})
                return context
            else:
                context = data_return(306, PostModuleActuator_MSG.get(306), {})
                return context
        else:
            logger.warning("错误的broker")
Exemplo n.º 2
0
    def run_bot_wait_list():

        # 检查当前任务数量是否大于3个
        task_queue_length = Xcache.get_module_task_length()
        if task_queue_length >= 3:
            return

        req = Xcache.pop_one_from_bot_wait()
        if req is None:
            return

        broker = req.get("broker")
        module_intent = req.get("module")
        if broker == BROKER.bot_msf_job:
            # 放入后台运行队列
            MSFModule.putin_post_msf_module_queue(module_intent)
        else:
            logger.error("unknow broker")