예제 #1
0
        public void Run()
        {
            _subscription = _connection.SubscribeAsync(Const.RankProcess, "rank_calculator", (sender, args) =>
            {
                var id      = Encoding.UTF8.GetString(args.Message.Data);
                var shard   = _redisStorage.LoadShard(id);
                var textKey = Const.TextTitleKey + id;

                if (!_redisStorage.IsKeyExist(textKey, shard))
                {
                    _logger.LogWarning("Text key {textKey} doesn't exists", textKey);
                    return;
                }

                var text = _redisStorage.Load(textKey, shard);
                var rank = CalculateRank(text).ToString();

                _logger.LogInformation("Shard: " + shard + ", id: " + id + ", text: " + text + ", rank: " + rank);

                _redisStorage.Store(Const.RankTitleKey + id, rank, shard);

                var message = $"Event: RankCalculated, context id: {id}, rank: {rank}";
                _connection.Publish(Const.BrokerRank, Encoding.UTF8.GetBytes(message));
            });

            _subscription.Start();

            Console.WriteLine("Press Enter to exit (RankCalculator)");
            Console.ReadLine();

            _subscription.Unsubscribe();

            _connection.Drain();
            _connection.Close();
        }
예제 #2
0
        public void OnGet(string id)
        {
            var shard = _redisStorage.LoadShard(id);

            _logger.LogDebug($"{shard} : {id} - SummaryGet");

            var rankKey = Const.RankTitleKey + id;

            Similarity = Convert.ToDouble(_redisStorage.Load(Const.SimilarityTitleKey + id, shard));

            for (int retryCount = 0; retryCount < 100; retryCount++)
            {
                Thread.Sleep(10);
                if (_redisStorage.IsKeyExist(rankKey, shard))
                {
                    Rank = Convert.ToDouble(_redisStorage.Load(rankKey, shard));
                    return;
                }
            }
            _logger.LogWarning($"RankKey {rankKey} doesn't exists in [{shard}]");
        }