|
@@ -97,15 +97,26 @@ class CustomizedPushObject:
|
|
|
try:
|
|
|
gateway_push_qs = GatewayPush.objects.filter(user_id__in=user_id_list, app_bundle_id__in=app_bundle_id_list).\
|
|
|
values('user_id', 'app_bundle_id', 'push_type', 'token_val')
|
|
|
- for gateway_push in gateway_push_qs:
|
|
|
- # 异步推送消息
|
|
|
- push_kwargs['gateway_push'] = gateway_push
|
|
|
- push_thread = threading.Thread(
|
|
|
- target=cls.start_push,
|
|
|
- kwargs=push_kwargs)
|
|
|
- push_thread.start()
|
|
|
-
|
|
|
- CUSTOMIZED_PUSH_LOGGER.info('customized_push_id:{}推送完成'.format(kwargs['id']))
|
|
|
+ if gateway_push_qs.exists():
|
|
|
+ sys_msg_list = []
|
|
|
+ saved_user_id_list = []
|
|
|
+ for gateway_push in gateway_push_qs:
|
|
|
+ # user_id保存列表,避免重复写入数据
|
|
|
+ user_id = gateway_push['user_id']
|
|
|
+ if user_id not in saved_user_id_list:
|
|
|
+ saved_user_id_list.append(user_id)
|
|
|
+ sys_msg_list.append(SysMsgModel(
|
|
|
+ userID_id=user_id, title=title, msg=msg, jumpLink=link, addTime=n_time, updTime=n_time))
|
|
|
+
|
|
|
+ # 异步推送消息
|
|
|
+ push_kwargs['gateway_push'] = gateway_push
|
|
|
+ push_thread = threading.Thread(
|
|
|
+ target=cls.start_push,
|
|
|
+ kwargs=push_kwargs)
|
|
|
+ push_thread.start()
|
|
|
+
|
|
|
+ SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
+ CUSTOMIZED_PUSH_LOGGER.info('customized_push_id:{}推送完成'.format(kwargs['id']))
|
|
|
except Exception as e:
|
|
|
CUSTOMIZED_PUSH_LOGGER.info('定制化推送或保存数据异常,'
|
|
|
'error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -124,26 +135,10 @@ class CustomizedPushObject:
|
|
|
app_bundle_id = gateway_push['app_bundle_id']
|
|
|
token_val = gateway_push['token_val']
|
|
|
|
|
|
- CUSTOMIZED_PUSH_LOGGER.info('准备推送: {}'.format(user_id))
|
|
|
push_succeed = cls.push_msg(push_type, app_bundle_id, token_val, n_time, title, msg, icon_link)
|
|
|
|
|
|
- # 推送成功,写入系统消息
|
|
|
- if push_succeed:
|
|
|
- info = '{}推送成功'
|
|
|
-
|
|
|
- # 已存表用户保存到redis列表,推送成功不再保存数据,避免重复保存
|
|
|
- redis_obj = RedisObject()
|
|
|
- key = 'customized_pushed_user_list'
|
|
|
- customized_pushed_user_list = redis_obj.lrange(key, 0, -1)
|
|
|
- if user_id not in customized_pushed_user_list:
|
|
|
- redis_obj.rpush(key, user_id)
|
|
|
- SysMsgModel.objects.create(
|
|
|
- userID_id=user_id, title=title, msg=msg, jumpLink=link, addTime=n_time, updTime=n_time
|
|
|
- )
|
|
|
- info += ',存表成功'
|
|
|
- CUSTOMIZED_PUSH_LOGGER.info(info.format(user_id))
|
|
|
- else:
|
|
|
- CUSTOMIZED_PUSH_LOGGER.info('用户{}推送失败,push_type:{}'.format(user_id, push_type))
|
|
|
+ push_status = '成功' if push_succeed else '失败'
|
|
|
+ CUSTOMIZED_PUSH_LOGGER.info('{}推送{},push_type:{}'.format(user_id, push_status, push_type))
|
|
|
|
|
|
@staticmethod
|
|
|
def push_msg(push_type, app_bundle_id, token_val, n_time, title, msg, icon_link):
|