public async Task <ActionResult <VoteMonitoringStats> > GetVoteMonitoringStats([FromQuery] string electionId) { try { if (string.IsNullOrWhiteSpace(electionId)) { electionId = Consts.FirstElectionRound; } var key = Consts.VoteMonitoringKey + electionId; var result = await _appCache.GetOrAddAsync( key, () => _resultsAggregator.GetVoteMonitoringStats(electionId), DateTimeOffset.Now.AddMinutes(5)); if (result.IsFailure) { _appCache.Remove(key); Log.LogWarning(result.Error); return(BadRequest(result.Error)); } return(result.Value); } catch (Exception e) { Log.LogError(e, "Exception encountered while retrieving vote monitoring stats"); return(StatusCode(500, e)); } }
private async Task SendUpdatedVoteMonitoringStats() { _logger.LogInformation($"Sending vote monitoring updates"); var stats = await _resultsAggregator.GetVoteMonitoringStats(); if (stats.IsSuccess) { await _hubContext.Clients.All.SendAsync("monitoring-updated", stats.Value); } }
public async Task <ActionResult <VoteMonitoringStats> > GetVoteMonitoringStats() { try { var result = await _appCache.GetOrAddAsync( Consts.VOTE_MONITORING_KEY, () => _resultsAggregator.GetVoteMonitoringStats(), DateTimeOffset.Now.AddMinutes(5)); if (result.IsFailure) { _appCache.Remove(Consts.VOTE_TURNOUT_KEY); _logger.LogError(result.Error); return(BadRequest(result.Error)); } return(result.Value); } catch (Exception e) { _logger.LogError(e, "Exception encountered while retrieving vote monitoring stats"); return(StatusCode(500, e)); } }