public async Task EveryFiveMinutesTick(CancellationToken token) { var fetched = await _eventStatusClient.GetEventStatus(); // init/ app-startup if (_storedCurrent == null) { _logger.LogDebug("Executing initial fetch"); _storedCurrent = fetched; return; } _logger.LogInformation("Checking status"); var bonusAdded = GetBonusAdded(fetched, _storedCurrent); if (bonusAdded != null) { _logger.LogInformation("Bonus added!"); await _mediator.Publish(bonusAdded, token); } var pointsReady = GetPointsReady(fetched, _storedCurrent); if (pointsReady != null) { _logger.LogInformation("Points ready!"); await _mediator.Publish(pointsReady, token); } _storedCurrent = fetched; }
public async Task EveryFiveMinutesTick(CancellationToken token) { EventStatusResponse fetched; try { fetched = await _eventStatusClient.GetEventStatus(); } catch (Exception e) when(LogError(e)) { return; } // init/ app-startup if (_storedCurrent == null) { _logger.LogDebug("Executing initial fetch"); _storedCurrent = fetched; return; } _logger.LogInformation("Checking status"); var bonusAdded = GetBonusAdded(fetched, _storedCurrent); if (bonusAdded != null) { _logger.LogInformation("Bonus added!"); await _session.Publish(bonusAdded); } var pointsReady = GetPointsReady(fetched, _storedCurrent); if (pointsReady != null) { _logger.LogInformation("Points ready!"); await _session.Publish(pointsReady); } var leaguesStatusChanged = fetched.Leagues != _storedCurrent.Leagues; if (leaguesStatusChanged && fetched.Leagues == EventStatusConstants.LeaguesStatus.Updated) { _logger.LogInformation($"League status changed from ${_storedCurrent.Leagues} to ${fetched.Leagues}"); await _session.Publish(new MatchdayLeaguesUpdated()); } _storedCurrent = fetched; }
public static PointsReady GetPointsReady(EventStatusResponse fetched, EventStatusResponse current) { var fetchedStatus = fetched.Status; var currentStatus = current.Status; foreach (EventStatus eventStatus in fetchedStatus) { var currentEventStatus = currentStatus.FirstOrDefault(c => c.Date == eventStatus.Date); if (currentEventStatus?.PointsStatus != EventStatusConstants.PointStatus.Ready && eventStatus.PointsStatus == EventStatusConstants.PointStatus.Ready) { return(new PointsReady(eventStatus.Event, DateTime.ParseExact(eventStatus.Date, "yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo).Date)); } } return(null); }
public static BonusAdded GetBonusAdded(EventStatusResponse fetched, EventStatusResponse current) { var fetchedStatus = fetched.Status; var currentStatus = current.Status; foreach (EventStatus eventStatus in fetchedStatus) { var currentEventStatus = currentStatus.FirstOrDefault(c => c.Date == eventStatus.Date); if (currentEventStatus?.BonusAdded == false && eventStatus.BonusAdded) { return(new BonusAdded(eventStatus.Event, DateTime.ParseExact(eventStatus.Date, "yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo).Date)); } } return(null); }