Commit 371576d9 authored by 段英荣's avatar 段英荣

Merge branch 'add_mysql_client' into 'master'

try except sys.exit and change mysql slave

See merge request !441
parents 4396340f e3b0207c
...@@ -16,6 +16,7 @@ from search.utils.common import * ...@@ -16,6 +16,7 @@ from search.utils.common import *
import libs.tools as Tools import libs.tools as Tools
from trans2es.models.pictorial import CommunityPictorialHomeFeed from trans2es.models.pictorial import CommunityPictorialHomeFeed
from libs.error import logging_exception from libs.error import logging_exception
import sys
class KafkaManager(object): class KafkaManager(object):
consumser_obj = None consumser_obj = None
...@@ -77,8 +78,8 @@ class CollectData(object): ...@@ -77,8 +78,8 @@ class CollectData(object):
have_read_topic_id_list = Tools.get_have_read_topic_id_list(device_id,user_id,TopicPageType.HOME_RECOMMEND) have_read_topic_id_list = Tools.get_have_read_topic_id_list(device_id,user_id,TopicPageType.HOME_RECOMMEND)
have_read_lin_pictorial_id_list = Tools.get_have_read_lin_pictorial_id_list(device_id, user_id, have_read_lin_pictorial_id_list = Tools.get_have_read_lin_pictorial_id_list(device_id, user_id,
TopicPageType.HOME_RECOMMEND) TopicPageType.HOME_RECOMMEND)
promote_recommend_topic_id_list = TopicHomeRecommend.objects.using(settings.SLAVE_DB_NAME).filter(is_online=1).values_list("topic_id",flat=True) promote_recommend_topic_id_list = TopicHomeRecommend.objects.using(settings.SLAVE1_DB_NAME).filter(is_online=1).values_list("topic_id",flat=True)
promote_lin_pictorial_id_list = CommunityPictorialHomeFeed.objects.using(settings.SLAVE_DB_NAME).filter( promote_lin_pictorial_id_list = CommunityPictorialHomeFeed.objects.using(settings.SLAVE1_DB_NAME).filter(
is_deleted=0, is_online=1).values_list("pictorial_id", flat=True) is_deleted=0, is_online=1).values_list("pictorial_id", flat=True)
have_read_topic_id_list.extend(promote_recommend_topic_id_list) have_read_topic_id_list.extend(promote_recommend_topic_id_list)
have_read_lin_pictorial_id_list.extend(promote_lin_pictorial_id_list) have_read_lin_pictorial_id_list.extend(promote_lin_pictorial_id_list)
...@@ -190,13 +191,13 @@ class CollectData(object): ...@@ -190,13 +191,13 @@ class CollectData(object):
# if collection and is_ai: # if collection and is_ai:
# click_topic_tag_list.append(id) # click_topic_tag_list.append(id)
topic_tag_list = list() topic_tag_list = list()
click_results = TopicTag.objects.using(settings.SLAVE_DB_NAME).filter( click_results = TopicTag.objects.using(settings.SLAVE1_DB_NAME).filter(
topic_id=topic_id, is_online=True).values_list("tag_id", "is_collection") topic_id=topic_id, is_online=True).values_list("tag_id", "is_collection")
for tag_id, is_collection in click_results: for tag_id, is_collection in click_results:
# topic_tag_list.append(tag_id) # topic_tag_list.append(tag_id)
if is_collection: if is_collection:
topic_tag_list.append(tag_id) topic_tag_list.append(tag_id)
tag_query_results = Tag.objects.using(settings.SLAVE_DB_NAME).filter( tag_query_results = Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
id__in=topic_tag_list, is_online=True, is_deleted=False, is_category=False).values_list("id", id__in=topic_tag_list, is_online=True, is_deleted=False, is_category=False).values_list("id",
"is_ai") "is_ai")
for id, is_ai in tag_query_results: for id, is_ai in tag_query_results:
...@@ -211,7 +212,7 @@ class CollectData(object): ...@@ -211,7 +212,7 @@ class CollectData(object):
device_id = raw_val_dict["device"]["device_id"] device_id = raw_val_dict["device"]["device_id"]
user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None
if query_type=="do": if query_type=="do":
tag_list = list(Tag.objects.using(settings.SLAVE_DB_NAME).filter(name=tag_name,is_online=True,is_deleted=False, is_category=False).values_list("id",flat=True)) tag_list = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(name=tag_name,is_online=True,is_deleted=False, is_category=False).values_list("id",flat=True))
click_topic_tag_list.extend(tag_list) click_topic_tag_list.extend(tag_list)
logging.info("query tag attention,positive tag_list,device_id:%s,query_name:%s,tag_list:%s" % ( logging.info("query tag attention,positive tag_list,device_id:%s,query_name:%s,tag_list:%s" % (
str(device_id), tag_name, str(click_topic_tag_list))) str(device_id), tag_name, str(click_topic_tag_list)))
...@@ -296,7 +297,7 @@ class CollectData(object): ...@@ -296,7 +297,7 @@ class CollectData(object):
# if len(exposure_sql_query_results)>0: # if len(exposure_sql_query_results)>0:
if len(tagid_list) > 0: if len(tagid_list) > 0:
tag_query_results = list(Tag.objects.using(settings.SLAVE_DB_NAME).filter( tag_query_results = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
id__in=tagid_list, is_online=True, is_deleted=False, id__in=tagid_list, is_online=True, is_deleted=False,
is_category=False).values_list("id",flat =True)) is_category=False).values_list("id",flat =True))
is_click = 1 is_click = 1
...@@ -319,4 +320,5 @@ class CollectData(object): ...@@ -319,4 +320,5 @@ class CollectData(object):
except: except:
logging_exception() logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
sys.exit()
return False return False
...@@ -29,7 +29,7 @@ class LinUCB: ...@@ -29,7 +29,7 @@ class LinUCB:
cls.default_tag_list = json.loads(redis_tag_data) if redis_tag_data else [] cls.default_tag_list = json.loads(redis_tag_data) if redis_tag_data else []
if len(cls.default_tag_list) == 0: if len(cls.default_tag_list) == 0:
cls.default_tag_list = Tag.objects.using(settings.SLAVE_DB_NAME).filter(is_online=True,collection=1).values_list("id",flat=True)[0:100] cls.default_tag_list = Tag.objects.using(settings.SLAVE1_DB_NAME).filter(is_online=True,collection=1).values_list("id",flat=True)[0:100]
return cls.default_tag_list return cls.default_tag_list
except: except:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment