Commit 48ed8b6d authored by 张彦钊's avatar 张彦钊

增加缓存视频cache_video_id

parent 24b77ddc
...@@ -13,7 +13,7 @@ import time ...@@ -13,7 +13,7 @@ import time
from config import * from config import *
def get_video_id(): def get_video_id(cache_video_id):
db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle') db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle')
cursor = db.cursor() cursor = db.cursor()
sql = "select diary_id from feed_diary_boost;" sql = "select diary_id from feed_diary_boost;"
...@@ -24,7 +24,7 @@ def get_video_id(): ...@@ -24,7 +24,7 @@ def get_video_id():
print(df.head(1)) print(df.head(1))
db.close() db.close()
if df.empty: if df.empty:
return False return cache_video_id
else: else:
video_id = df[0].values.tolist() video_id = df[0].values.tolist()
return video_id return video_id
...@@ -112,7 +112,7 @@ def get_score(queue_arg): ...@@ -112,7 +112,7 @@ def get_score(queue_arg):
def update_dairy_queue(score_df,predict_score_df,total_video_id): def update_dairy_queue(score_df,predict_score_df,total_video_id):
diary_id = score_df["cid"].values.tolist() diary_id = score_df["cid"].values.tolist()
if total_video_id: if total_video_id != []:
video_id = list(set(diary_id)&set(total_video_id)) video_id = list(set(diary_id)&set(total_video_id))
if len(video_id)>0: if len(video_id)>0:
not_video = list(set(diary_id) - set(video_id)) not_video = list(set(diary_id) - set(video_id))
...@@ -145,7 +145,7 @@ def update_dairy_queue(score_df,predict_score_df,total_video_id): ...@@ -145,7 +145,7 @@ def update_dairy_queue(score_df,predict_score_df,total_video_id):
score_df = score_df.sort_values(by="score", ascending=False) score_df = score_df.sort_values(by="score", ascending=False)
# print("分数合并成功1") # print("分数合并成功1")
return score_df.index.tolist() return score_df.index.tolist()
# 如果total_video_id是空 # 如果total_video_id是空列表
else: else:
score_df = score_df.set_index(["cid"]) score_df = score_df.set_index(["cid"])
predict_score_df = predict_score_df.set_index(["cid"]) predict_score_df = predict_score_df.set_index(["cid"])
...@@ -155,7 +155,6 @@ def update_dairy_queue(score_df,predict_score_df,total_video_id): ...@@ -155,7 +155,6 @@ def update_dairy_queue(score_df,predict_score_df,total_video_id):
return score_df.index.tolist() return score_df.index.tolist()
def update_sql_dairy_queue(queue_name, diary_id,device_id, city_id): def update_sql_dairy_queue(queue_name, diary_id,device_id, city_id):
db = pymysql.connect(host='rm-m5e842126ng59jrv6.mysql.rds.aliyuncs.com', port=3306, user='doris', db = pymysql.connect(host='rm-m5e842126ng59jrv6.mysql.rds.aliyuncs.com', port=3306, user='doris',
passwd='o5gbA27hXHHm', db='doris_prod') passwd='o5gbA27hXHHm', db='doris_prod')
...@@ -238,9 +237,12 @@ def multi_proecess_update(device_id, city_id, data_set_cid,total_video_id): ...@@ -238,9 +237,12 @@ def multi_proecess_update(device_id, city_id, data_set_cid,total_video_id):
if __name__ == "__main__": if __name__ == "__main__":
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
total_number = 0 total_number = 0
# 增加缓存日记视频列表
cache_video_id = []
while True: while True:
data_set_cid = pd.read_csv(DIRECTORY_PATH + "data_set_cid.csv")["cid"].values.tolist() data_set_cid = pd.read_csv(DIRECTORY_PATH + "data_set_cid.csv")["cid"].values.tolist()
total_video_id = get_video_id() total_video_id = get_video_id(cache_video_id)
cache_video_id = total_video_id
device_city_list = get_active_users() device_city_list = get_active_users()
total_number += len(device_city_list) total_number += len(device_city_list)
print("累计预测用户总数:{}".format(total_number)) print("累计预测用户总数:{}".format(total_number))
......
import os
import time
def check():
out = os.popen("ps aux | grep diaryQueueUpdate.py").read()
flag = 1
for line in out.splitlines():
if 'python diaryQueueUpdate.py' in line:
flag = 2
return flag
if __name__ == "__main__":
while True:
if check() == 1:
os.popen('python diaryQueueUpdate.py')
print("成功重启diaryQueueUpdate")
time.sleep(300)
\ No newline at end of file
...@@ -17,7 +17,8 @@ if __name__ == "__main__": ...@@ -17,7 +17,8 @@ if __name__ == "__main__":
end_train = time.time() end_train = time.time()
print("训练模型耗时{}分".format((end_train-start_train)/60)) print("训练模型耗时{}分".format((end_train-start_train)/60))
move_file() move_file()
kill_process() #TODO 如果用自己写的keepProcess文件守护进程,下面在这个函数里删掉重新启动进程那行代码,因为可能会多启动一次进程
restart_process()
......
...@@ -55,13 +55,22 @@ def move_file(): ...@@ -55,13 +55,22 @@ def move_file():
print("成功将文件剪切到对应路径") print("成功将文件剪切到对应路径")
def kill_process(): def restart_process():
out = os.popen("ps aux | grep diaryQueueUpdate.py").read() out = os.popen("ps aux | grep diaryQueueUpdate.py").read()
for line in out.splitlines(): for line in out.splitlines():
if 'python diaryQueueUpdate.py' in line: if 'python diaryQueueUpdate.py' in line:
pid = int(line.split()[1]) pid = int(line.split()[1])
# 有些进程的生命周期非常短或者随时可能结束,一定要捕捉这个异常
try:
os.kill(pid, signal.SIGKILL) os.kill(pid, signal.SIGKILL)
print("已杀死python diaryQueueUpdate.py 进程") print("已杀死python diaryQueueUpdate.py 进程")
except OSError:
print('没有如此进程!!!')
os.popen('python diaryQueueUpdate.py')
print("成功重启diaryQueueUpdate")
else:
os.popen('python diaryQueueUpdate.py')
print("成功重启diaryQueueUpdate")
# 把数据写到redis里 # 把数据写到redis里
......
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