def serve(): # 创建recommend日志 lg.create_logger() # 多线程服务器 server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # 注册本地服务 user_reco_pb2_grpc.add_UserRecommendServicer_to_server( UserRecommendServicer(), server) # 监听端口 server.add_insecure_port(DefaultConfig.RPC_SERVER) # 开始接收请求进行服务 server.start() # 使用 ctrl+c 可以退出服务 _ONE_DAY_IN_SECONDS = 60 * 60 * 24 try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)
client = self.client def computeFunction(rdd): for row in rdd.collect(): channel_id, article_id = row.split(',') logger.info( "{}, INFO: get kafka new_article each data:channel_id{}, article_id{}" .format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), channel_id, article_id)) client.zadd("ch:{}:new".format(channel_id), {article_id: time.time()}) NEW_ARTICLE_DS.map(lambda x: x[1]).foreachRDD(computeFunction) if __name__ == '__main__': import setting.logging as lg lg.create_logger() ore = OnlineRecall() ore._update_content_recall() ore._update_hot_redis() ore._update_new_redis() stream_sc.start() # 使用 ctrl+c 可以退出服务 _ONE_DAY_IN_SECONDS = 60 * 60 * 24 try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: pass