private void DoWork(object state) { var stopWatch = new Stopwatch(); stopWatch.Start(); _logger?.LogInformation("Fetching news feeds started"); var rawFeeds = _reader.ReadAll().Result.ToList(); rawFeeds.ForEach(rawFeed => { var feed = _converter.Convert(rawFeed.Id, rawFeed); _store.InsertAsync(feed); }); stopWatch.Stop(); _logger?.LogInformation($"Fetching news feeds finished in {stopWatch.Elapsed.Seconds} seconds. Total feeds: {rawFeeds.Count}"); }
public async Task <IActionResult> Convert() { using (var reader = new StreamReader(HttpContext.Request.Body)) { var content = await reader.ReadToEndAsync(); _logger?.LogInformation("Converter received event: " + content); dynamic json = JValue.Parse(content); var attributes = json.message.attributes; var eventType = attributes.eventType; if (eventType != "OBJECT_FINALIZE") { return(Ok()); } try { var stopWatch = new Stopwatch(); stopWatch.Start(); var feedId = (string)attributes.objectId; _logger.LogInformation($"Reading raw feed: {feedId}"); var rawFeed = await _syndStore.ReadAsync(feedId); _logger.LogInformation($"Converting raw feed: {feedId}"); var feed = _converter.Convert(feedId, rawFeed); _logger.LogInformation($"Inserting into backend: {feedId}"); await _store.InsertAsync(feed); stopWatch.Stop(); _logger?.LogInformation($"Converting feed finished in {stopWatch.Elapsed.Seconds} seconds."); } catch (Exception e) { _logger.LogError($"Error reading or converting feed: {e.Message}"); } } return(Ok()); }