Esempio n. 1
0
    def deal_with_result_data(self, task_dict):
        """
		按服务器IP注册队列
		:param task_dict:
		:return:
		"""
        """获取休眠时间"""
        account_sleep_time = BusiBaseConfService().search_key_return_value(
            (busi_config.ACCOUNT_SLEEP_TIME))
        sleep_time = account_sleep_time.split("|")
        time_out = random.randint(int(sleep_time[0]), int(sleep_time[1]))
        while task_dict:
            """按服务器生成队列"""
            server_dict = {}
            queue_length = 0
            for key in list(task_dict.keys()):
                """判断是否为空"""
                if not task_dict[key]:
                    del task_dict[key]
                    continue
                """取值"""
                item = task_dict[key].pop()
                queue_length += 1
                server_ip_name = "get_%s_queue" % item.get("serverIp").replace(
                    ".", "_")
                if server_ip_name in task_dict:
                    server_dict[server_ip_name].append(item)
                else:
                    server_dict.setdefault(server_ip_name, [])
                    server_dict[server_ip_name].append(item)
            """判空"""
            if task_dict:
                self.redis_queue_manager_helper(server_dict)
                self.logger.info("账号休眠,休眠时长:%s秒" % time_out)
                time.sleep(time_out)
    def update(self):
        """
		筛选发送服务器
		:return:
		"""
        self.logger.info("【数据提取】3、筛选服务器")
        result = self.subject.email_item
        """查询服务器数据"""
        server_list = ServerConfService().search()
        """查询筛选规则"""
        resend_rules = BusiBaseConfService().search_key_return_value(
            (busi_config.RESEND_RULES), "1|1|1")
        """分割规则"""
        resend_rules_list = resend_rules.split("|")
        """判断是否有服务器IP"""
        server_ip = result.get("serverIp", "")
        if server_ip:
            """服务器IP存在,筛选当前服务器信息"""
            server_item = self.select_server_ip(server_list, server_ip)
        else:
            """待过滤服务器ip"""
            filter_ip = result.get("reSendServerIp", "")
            """筛选服务器"""
            if not filter_ip:
                filter_ip = ""
            server_item = self.filter_server_ip(server_list,
                                                resend_rules_list[0],
                                                filter_ip)
        if not server_item:
            raise BusinessExcetion("T04", "未查到有效的服务器地址")
        self.logger.info("【任务队列】筛选服务器IP:%s" % server_item.get("serverIp"))
        result.update(server_item)
        """更新/添加使用量"""
    def update(self):
        """
		选择发送内容
		:return:
		"""
        self.logger.info("【任务队列】2、筛选发送内容")
        result = self.subject.email_item
        """当前task_code"""
        task_code = result.get("task_code")
        """查询发送内容"""
        template_list = TemplateService().search(task_code)
        """查询筛选规则"""
        resend_rules = BusiBaseConfService().search_key_return_value(
            (busi_config.RESEND_RULES), "1|1|1")
        """分割规则"""
        resend_rules_list = resend_rules.split("|")
        """判断是否有发送内容"""
        template_ext_code = result.get("templateExtCode", "")
        if template_ext_code:
            """发送内容存在,筛选当前发送内容"""
            send_email_content_item = self.select_send_email_content(
                template_list, template_ext_code)
        else:
            """待过滤发送内容"""
            filter_template_ext_code = result.get("reSendTemplateExtCode", "")
            if not filter_template_ext_code:
                filter_template_ext_code = ""
            """筛选发送内容"""
            send_email_content_item = self.filter_send_template_ext_code(
                template_list, resend_rules_list[2], filter_template_ext_code)
        if not send_email_content_item:
            raise BusinessExcetion("T02", "未查到有效邮件内容,进行回滚")
        self.logger.info("【任务队列】筛选发送内容:%s" %
                         send_email_content_item.get("templateExtCode"))
        result.update(send_email_content_item)
Esempio n. 4
0
    def get_send_min_max_time(self):
        """
		获取发送时间段
		:return:
		"""
        send_min_max_time = BusiBaseConfService().search_key_return_value(
            (busi_config.SEND_MIN_MAX_TIME), "9|20")
        """数据分割"""
        min_time, max_time = send_min_max_time.split("|")
        return [min_time, max_time]
Esempio n. 5
0
    def get_batch_sleep_time(self):
        """
		获取休眠时间
		:return:
		"""
        batch_sleep_time = BusiBaseConfService().search_key_return_value(
            (busi_config.BUSI_BATCH_SLEEP_TIME), "5|8")
        min_time, max_time = batch_sleep_time.split("|")
        """休眠时长"""
        time_out = random.randint(int(min_time), int(max_time))
        return time_out
Esempio n. 6
0
    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())
Esempio n. 7
0
	def update(self):
		"""
		筛选发送账号
		:return:
		"""
		self.logger.info("【任务队列】1、筛选发送账号")
		result = self.subject.email_item
		"""当前IP"""
		public_ip = result.get("public_ip")
		account_list = SendEmailAccountService().search_valid_account(public_ip)
		if not account_list:
			self.logger.info("【发送邮件】开始变更账号信息")
			account_reopen_time = BusiBaseConfService().search_key_return_value((busi_config.ACCOUNT_REOPEN_TIME))
			SendEmailAccountService().search_and_update_account(public_ip, int(account_reopen_time))
			raise BusinessExcetion("T02", "未查询到有效账号")
		"""查询筛选规则"""
		resend_rules = BusiBaseConfService().search_key_return_value((busi_config.RESEND_RULES),"1|1|1")
		"""分割规则"""
		resend_rules_list = resend_rules.split("|")
		"""判断是否有发送账号"""
		send_account = result.get("sendAccount", "")
		if send_account:
			"""发送账号存在,筛选当前账号信息"""
			send_account_item = self.select_send_account(account_list, send_account)
		else:
			"""待过滤发送账号"""
			filter_send_account = result.get("reSendAccount", "")
			if not filter_send_account:
				filter_send_account = ""
			"""筛选发送账号"""
			send_account_item = self.filter_send_account(account_list, resend_rules_list[1], filter_send_account)
		if not send_account_item:
			raise BusinessExcetion("T02", "未查到有效账号,进行回滚")
		self.logger.info("【任务队列】筛选发送账号:%s" % send_account_item.get("userName"))
		result.update(send_account_item)
		self.set_used_of_count_record(send_account_item.get("userName"), 2)
Esempio n. 8
0
	def task_extract_time(self):
		"""
		定时任务
		:return:
		"""
		send_count = 0
		send_report = 0
		while True:
			self.logger.info("=============================浮屠长生 开始第[%s]定时任务==================================" % send_count)
			"""获取发送时间段"""
			send_min_max_time = BusiBaseConfService().search_key_return_value((busi_config.SEND_MIN_MAX_TIME), "9|20")
			"""数据分割"""
			send_time = send_min_max_time.split("|")
			"""获取休眠时间"""
			batch_sleep_time = BusiBaseConfService().search_key_return_value((busi_config.BUSI_BATCH_SLEEP_TIME), "5|8")
			sleep_time = batch_sleep_time.split("|")
			"""获取允许重发的ip"""
			allow_resend_server_ip = BusiBaseConfService().search_key_return_value((busi_config.ALLOW_RESEND_SERVER_IP))

			"""休眠时长"""
			time_out = random.randint(int(sleep_time[0]), int(sleep_time[1]))
			"""获取当前时间"""
			hour = int(time.strftime('%H', time.localtime(time.time())))
			if hour > int(send_time[1]):
				"""
				收取邮件
				"""
				Collect().instance_server_ip()
				self.logger.info("当前时间未在发送时间段内容,进行休眠,休眠时长[%s]分钟" % time_out)
				time.sleep(60 * time_out)
			elif hour < int(send_time[0]):
				"""判断是否在发送时间段内,如果不存在的话跳过 0~9"""
				"""若标志位为0"""
				if send_report == 0 and allow_resend_server_ip == self.public_ip and self.get_task_list():
					send_report = 1
					"""更新账号"""
					SendEmailAccountService().update_all_status_valid()
				send_count = 0
				self.logger.info("当前时间未在发送时间段内容,进行休眠,休眠时长[%s]分钟" % time_out)
				time.sleep(60 * time_out)
			elif not self.search_task_code_by_server_ip():
				self.logger.info("【提取数据】不存在发送中的任务,流程结束")
				time.sleep(60 * time_out)
			elif send_count != 0 and not self.get_task_list():
				"""如果不是当天第一次发送,且缓存记录为空"""
				"""发送次数"""
				send_count += 1
				send_report = 0
				"""
				收取邮件
				"""
				Collect().instance_server_ip()
				"""
				数据二次营销 大于5次就不再营销
				"""
				if allow_resend_server_ip == self.public_ip:
					self.resend_instance()
				self.instance()
				"""休眠"""
				self.logger.info("当前第[%s]次发送,提取完成,进行休眠,休眠时长[%s]分钟" % (send_count, time_out))
				time.sleep(60 * time_out)
			elif self.get_task_list():
				"""如果缓存记录不为空,则休眠"""
				send_report = 0
				self.logger.info("当前第[%s]次发送,缓存信息不为空,进行休眠,休眠时长[%s]分钟" % (send_count, time_out))
				time.sleep(60 * time_out)
			else:
				"""如果缓存记录为空,进行消费生产"""
				send_count += 1
				send_report = 0
				"""生产"""
				self.instance()
				self.logger.info("当前第[%s]次发送,生成缓存信息,进行休眠,休眠时长[%s]分钟" % (send_count, time_out))
				time.sleep(60*time_out)
			self.logger.info("=============================浮屠长生 结束本次定时任务==================================")
Esempio n. 9
0
 def get_consume_sleep_time(self):
     consume_sleep_time = BusiBaseConfService().search_key_return_value(
         (busi_config.CONSUME_SLEEP_TIME))
     sleep_time = consume_sleep_time.split("|")
     time_out = random.randint(int(sleep_time[0]), int(sleep_time[1]))
     return time_out