public IList <OccupationMatch> GetPredictionsForGetOccupationMatches(IList <OccupationMatch> matches) { if (matches == null || matches.Count == 0) { return(matches); } var tasks = new List <Task>(); foreach (var match in matches) { tasks.Add(Task.Run(async() => { var cachedResult = await CheckCachedLmiData(match.SocCode); if (cachedResult == JobGrowth.Undefined) { var prediction = await GetPredictionsForSocCode(match.SocCode, PredictionFilter.Region); if (prediction != null) { match.JobGrowth = LmiHelper.DetermineJobSectorGrowth(prediction); } await CacheLmiData(match.SocCode, match.JobGrowth); } else { match.JobGrowth = cachedResult; } })); } var t = Task.WhenAll(tasks); t.Wait(); return(matches); }
public void When_LastCheckedDate_IsOutOfDate_ReturnFalse() { var date = DateTimeOffset.Now.AddDays(366); var result = LmiHelper.IsOutOfDate(date, 365); result.Should().BeFalse(); }
internal async Task <JobGrowth> CheckCachedLmiData(int socCode) { if (socCode <= 0) { return(JobGrowth.Undefined); } var result = await _cosmosService.ReadItemAsync(id : socCode.ToString(), String.Empty, CosmosCollection.LmiData); if (result.IsSuccessStatusCode) { var lmiData = JsonConvert.DeserializeObject <CachedLmiData>(await result.Content.ReadAsStringAsync()); var isOutOfDate = LmiHelper.IsOutOfDate(lmiData.DateWritten, _lmiSettings.Value.CacheLifespan); if (!isOutOfDate) { return(lmiData.JobGrowth); } } return(JobGrowth.Undefined); }