public Communicator(ILogger <Communicator> logger, Mapper mapper, ISlackService slackService) { client = new HttpClient { Timeout = TimeSpan.FromSeconds(15) }; this.logger = logger; this.mapper = mapper; this.slackService = slackService; statsCache = new ArrayEndpointCache <StatsDaily>(); regionCache = new ArrayEndpointCache <RegionsDay>(); patientsCache = new ArrayEndpointCache <PatientsDay>(); hospitalsCache = new ArrayEndpointCache <HospitalsDay>(); hospitalsListCache = new ArrayEndpointCache <Hospital>(); municipalitiesListCache = new ArrayEndpointCache <Municipality>(); retirementHomesListCache = new ArrayEndpointCache <RetirementHome>(); retirementHomesCache = new ArrayEndpointCache <RetirementHomesDay>(); deceasedPerRegionsDayCache = new ArrayEndpointCache <DeceasedPerRegionsDay>(); municipalityDayCache = new ArrayEndpointCache <MunicipalityDay>(); healthCentersDayCache = new ArrayEndpointCache <HealthCentersDay>(); statsWeeklyDayCache = new ArrayEndpointCache <StatsWeeklyDay>(); owidCountriesCache = new DictionaryEndpointCache <string, Models.Owid.Country>(); monthlyDeathsSloveniaCache = new ArrayEndpointCache <MonthlyDeathsSlovenia>(); labTestsCache = new ArrayEndpointCache <LabTestDay>(); dailyDeathsSloveniaCache = new ArrayEndpointCache <DailyDeathsSlovenia>(); ageDailyDeathsSloveniaCache = new ArrayEndpointCache <AgeDailyDeathsSloveniaDay>(); errors = new ConcurrentDictionary <string, object>(); }
public Communicator(ILogger <Communicator> logger, Mapper mapper, ISlackService slackService) { client = new HttpClient { Timeout = TimeSpan.FromSeconds(15) }; this.logger = logger; this.mapper = mapper; this.slackService = slackService; statsCache = new(); patientsCache = new(); hospitalsCache = new(); hospitalsListCache = new(); municipalitiesListCache = new(); retirementHomesListCache = new(); retirementHomesCache = new(); municipalityCache = new(); regionCasesCache = new(); healthCentersDayCache = new(); statsWeeklyDayCache = new(); owidCountriesCache = new(); monthlyDeathsSloveniaCache = new(); labTestsCache = new(); dailyDeathsSloveniaCache = new(); ageDailyDeathsSloveniaCache = new(); sewageCache = new(); schoolCasesCache = new(); schoolAbsencesCache = new(); schoolRegimesCache = new(); vaccinationsCache = new(); summaryCache = new SummaryCache(default, default, default, default, default, default, default);
public Communicator(ILogger <Communicator> logger, Mapper mapper, ISlackService slackService) { client = new HttpClient { Timeout = TimeSpan.FromSeconds(15) }; this.logger = logger; this.mapper = mapper; this.slackService = slackService; statsCache = new ArrayEndpointCache <StatsDaily>(); regionCache = new ArrayEndpointCache <RegionsDay>(); patientsCache = new ArrayEndpointCache <PatientsDay>(); hospitalsCache = new ArrayEndpointCache <HospitalsDay>(); hospitalsListCache = new ArrayEndpointCache <Hospital>(); municipalitiesListCache = new ArrayEndpointCache <Municipality>(); retirementHomesListCache = new ArrayEndpointCache <RetirementHome>(); retirementHomesCache = new ArrayEndpointCache <RetirementHomesDay>(); deceasedPerRegionsDayCache = new ArrayEndpointCache <DeceasedPerRegionsDay>(); municipalityDayCache = new ArrayEndpointCache <MunicipalityDay>(); healthCentersDayCache = new ArrayEndpointCache <HealthCentersDay>(); errors = new ConcurrentDictionary <string, object>(); }
async Task RefreshEndpointCache <TData>(string url, ArrayEndpointCache <TData> sync, Func <string, ImmutableArray <TData> > mapFromString) { var policy = HttpPolicyExtensions .HandleTransientHttpError() .RetryAsync(1); HttpResponseMessage response; try { response = await policy.ExecuteAsync(() => { var request = new HttpRequestMessage(HttpMethod.Get, url); RequestCount.WithLabels(url).Inc(); return(client.SendAsync(request)); }); if (response.IsSuccessStatusCode) { _ = ProcessErrorRemovalAsync(url); var timestamp = await GetTimestampAsync(url); IEnumerable <string> headerETags; response.Headers.TryGetValues("ETag", out headerETags); string newETag = headerETags != null?headerETags.SingleOrDefault() : null; string responseBody = await response.Content.ReadAsStringAsync(); sync.Cache = new ETagCacheItem <ImmutableArray <TData> >(newETag, responseBody, mapFromString(responseBody), timestamp); } else { _ = ProcessErrorAsync(url, response.ReasonPhrase); } } catch (Exception ex) { _ = ProcessErrorAsync(url, ex.Message); } }