public async Task ObserveAsync(string productName, string productUrl)
        {
            try
            {
                ISiteParser parser = _parserFactory.GetInstance(productUrl);

                ProductPriceFetchResult price = parser.Parse(productName, productUrl);

                if (price.Price <= 0)
                {
                    throw new Exception("Price is negative or zero");
                }

                await _priceStore.StoreAsync(price);
            }
            catch (Exception e)
            {
                var id = Guid.NewGuid().ToString("N");

                _logger.LogError(e, $"{id} Could not observe prices on site {productUrl}");

                var price = new ProductPriceFetchResult(e.Message, id, productName, productUrl);
                await _priceStore.StoreAsync(price);
            }
        }
示例#2
0
        public async Task IndexDocument(ProductPriceFetchResult productPrice)
        {
            IndexResponse response = _elastic.Index <ProductPriceFetchResult>(productPrice, i => i.Index("prices"));

            var debugInfo = response.DebugInformation;

            if (!response.IsValid)
            {
                throw response.OriginalException;
            }
        }
        public async Task StoreAsync(ProductPriceFetchResult productPrice)
        {
            try
            {
                await _pricesIndex.IndexDocument(productPrice);
            }
            catch (Exception e)
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(productPrice);

                _logger.LogError(e, $"Could not save {json}");
            }
        }