def main(): args = get_args() logger = get_logger("article_service", args.v) db_channel = get_service_channel(logger, "DB_SERVICE_HOST", 1798) db_stub = database_pb2_grpc.DatabaseStub(db_channel) create_channel = get_service_channel(logger, "CREATE_SERVICE_HOST", 1922) create_stub = create_pb2_grpc.CreateStub(create_channel) search_channel = get_service_channel(logger, "SEARCH_SERVICE_HOST", 1886) search_stub = search_pb2_grpc.SearchStub(search_channel) logger.info("Creating article server") mdc_channel = get_service_channel(logger, "MDC_SERVICE_HOST", 1937) mdc_stub = mdc_pb2_grpc.ConverterStub(mdc_channel) server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) users_util = UsersUtil(logger, db_stub) recommender_util = RecommendersUtil(logger, db_stub) post_recommendation_stub = recommender_util.get_post_recommendation_stub() article_pb2_grpc.add_ArticleServicer_to_server( ArticleServicer(create_stub, db_stub, mdc_stub, search_stub, logger, users_util, post_recommendation_stub), server) server.add_insecure_port('0.0.0.0:1601') logger.info("Starting article server on port 1601") server.start() try: while True: time.sleep(60 * 60 * 24) # One day except KeyboardInterrupt: db_channel.close() create_channel.close() pass
def __init__(self, logger, users_util, db_stub): self._logger = logger self._users_util = users_util self._db_stub = db_stub self._recommender_util = RecommendersUtil( logger, db_stub, self.DEFAULT_RECOMMENDER, self.ENV_VAR, self.RECOMMENDERS) # self.active_recommenders contains one or more recommender system # objects (out of the constructors in self.RECOMMENDERS). self.active_recommenders = self._recommender_util._get_active_recommenders()
def __init__(self, logger, users_util, db_stub): self._logger = logger self._db = db_stub self._recommender_util = RecommendersUtil(logger, db_stub) # Get user data and create models self.post_tag_freq = defaultdict(int) self.user_tag_freq = defaultdict(int) self.posts = self._get_all_posts_and_tags() self._logger.info("post-tags: {}".format(self.posts)) self.users = self._get_all_user() self.user_models = self._create_user_models(self.users) self._logger.info("user_models: {}".format(self.user_models)) # Calculate Inverse Frequencies self.user_tag_ifs = self._calculate_based_itf( self.user_tag_freq, len(self.user_models)) self.post_tag_ifs = self._calculate_based_itf( self.post_tag_freq, len(self.posts))
def main(): logger = get_logger("likes_service") db_stub = get_db_stub(logger) user_util = UsersUtil(logger, db_stub) activ_util = ActivitiesUtil(logger, db_stub) recommender_util = RecommendersUtil(logger, db_stub) post_recommendation_stub = recommender_util.get_post_recommendation_stub() server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) like_pb2_grpc.add_S2SLikeServicer_to_server( S2SLikeServicer(logger, db_stub, user_util, activ_util, post_recommendation_stub), server) server.add_insecure_port("0.0.0.0:1848") logger.info("Starting Like service on port 1848") server.start() try: while True: time.sleep(60 * 60 * 24) # One day except KeyboardInterrupt: pass
def main(): args = get_args() logger = get_logger('follows_service', args.v) logger.info('Creating server') db_env = 'DB_SERVICE_HOST' follow_env = 'FOLLOW_ACTIVITY_SERVICE_HOST' approver_env = 'APPROVER_SERVICE_HOST' rss_env = 'RSS_SERVICE_HOST' with get_service_channel(logger, db_env, 1798) as db_chan, \ get_service_channel(logger, follow_env, 1922) as follow_chan, \ get_service_channel(logger, approver_env, 2077) as approver_chan, \ get_service_channel(logger, rss_env, 1973) as rss_chan: db_stub = database_pb2_grpc.DatabaseStub(db_chan) rss_stub = rss_pb2_grpc.RSSStub(rss_chan) follow_stub = s2s_follow_pb2_grpc.S2SFollowStub(follow_chan) approver_stub = approver_pb2_grpc.ApproverStub(approver_chan) users_util = UsersUtil(logger, db_stub) util = Util(logger, db_stub, approver_stub, users_util) server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) recommender_util = RecommendersUtil(logger, db_stub) follow_recommender_stub = recommender_util.get_follow_recommender_stub( ) follows_servicer = FollowsServicer(logger, util, users_util, db_stub, follow_stub, approver_stub, rss_stub, follow_recommender_stub) follows_pb2_grpc.add_FollowsServicer_to_server(follows_servicer, server) server.add_insecure_port('0.0.0.0:1641') logger.info("Starting follows service on port 1641") server.start() try: while True: time.sleep(60 * 60 * 24) # One day except KeyboardInterrupt: pass