def redis_instance(self): """ 启动redis消费 :return: """ try: """获取订阅信息""" kafka_topic = "get_%s_queue" % self.task_choice_pattern.replace( ".", "_") """读取当前redis内数据长度""" queue_length = BusinessUtil.get_redis_llen_by_key(kafka_topic) """读取最大量""" consume_max_redis_read_length = BusiBaseConfService( ).search_key_return_value( (busi_config.CONSUME_MAX_REDIS_READ_LENGTH)) self.logger.info("单次最大处理量为:%s" % consume_max_redis_read_length) """读取redis列表""" result = BusinessUtil.get_redis_lpop_by_key_and_length( kafka_topic, queue_length, int(consume_max_redis_read_length)) """判空""" if not result: self.logger.info("【消费】未读取到有效数据,流程结束") return """处理消息""" self.processing_task(result) """处理结束""" self.logger.info("【消费】处理结束") except Exception as e: self.logger.error("【消费】启动消费异常,信息为:%s" % traceback.format_exc())
def instance(self): """ 调度处理任务队列数据 :return: """ try: """获取休眠时间""" product_sleep_time = BusiBaseConfService().search_key_return_value( (busi_config.PRODUCT_SLEEP_TIME)) sleep_time = product_sleep_time.split("|") time_out = random.randint(int(sleep_time[0]), int(sleep_time[1])) """判断是否存在发送中的任务 不存在 则直接返回""" if not self.search_task_code_by_server_ip(): self.logger.info("【服务进程】不存在发送中的任务,日常生成休眠,休眠时长:%s分" % time_out) time.sleep(time_out * 60) return """读取任务队列""" task_name_list = self.get_task_list() self.logger.info("【服务进程】任务列表为:%s" % task_name_list) if not task_name_list: self.logger.info("【服务进程】任务列表为空,日常生成休眠,休眠时长:%s分" % time_out) time.sleep(time_out * 60) return """判断账号""" if not self.check_valid_account(): self.logger.info("【服务进程】无有效账号,日常生成休眠,休眠时长:%s分" % time_out) time.sleep(time_out * 60) return """按任务优先级读取""" for task in task_name_list: queue_length = BusinessUtil.get_redis_llen_by_key(task) """队列为空""" if not queue_length or queue_length == 0: continue """出队列""" self.processing_task(task, queue_length) break except Exception as e: self.logger.error("【服务进程】服务进程异常,异常信息为:%s" % traceback.format_exc())