def check_valid_account(self): """ 校验有效邮箱 :return: """ account_list = SendEmailAccountService().search_valid_account( self.public_ip) if account_list: return True """获取账号重开间隔时间""" account_reopen_time = BusiBaseConfService().search_key_return_value( (busi_config.ACCOUNT_REOPEN_TIME)) """查询触发频率过快的账号剩余量, 如还有剩余,尝试重新激活""" return SendEmailAccountService().search_lock_account( int(account_reopen_time))
def get_send_email_account_list_by_server_ip(self): """ 通过ip查询账号 :return: """ result = SendEmailAccountService().search_pop_server_ip(self.public_ip) return result
def get_send_email_account_list(self): """ 获取当天邮件发送账号 :return: """ timeStr = str(time.strftime('%Y-%m-%d', time.localtime(time.time()))) start = "%s 00:00:00" % timeStr end = "%s 23:59:59" % timeStr result = UsedOfCountService().search_by_type((start, end)) if not result: """查询全部账号""" result = SendEmailAccountService().search_pop() return result
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)
def update(self): """ 账号状态检查 :return: """ """读取账号""" self.logger.info("【发送邮件】0、账号状态") result = self.subject.email_item """发送账号""" user_name = result.get("userName") """锁定账号""" not_lock_user_name = SendEmailAccountService( ).search_not_lock_user_name(user_name) if not_lock_user_name: return raise BusinessExcetion("T00", "该域名已被锁定,无法发送")
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("=============================浮屠长生 结束本次定时任务==================================")