public async Task Handle(VacancyPublishedEvent notification, CancellationToken cancellationToken) { var vacancyTask = _repository.GetVacancyAsync(notification.VacancyId); var programmeTask = _referenceDataReader.GetReferenceData <ApprenticeshipProgrammes>(); await Task.WhenAll(vacancyTask, programmeTask); var vacancy = vacancyTask.Result; var programme = programmeTask.Result.Data.Single(p => p.Id == vacancy.ProgrammeId); var liveVacancy = vacancy.ToVacancyProjectionBase <LiveVacancy>(programme, () => QueryViewType.LiveVacancy.GetIdValue(vacancy.VacancyReference.ToString()), _timeProvider); await _queryStoreWriter.UpdateLiveVacancyAsync(liveVacancy); }
private async Task RegenerateLiveVacancies(List <Guid> liveVacancyIds, List <ApprenticeshipProgramme> programmes) { var watch = Stopwatch.StartNew(); var deletedCount = await _queryStoreWriter.DeleteAllLiveVacancies(); foreach (var vacancyId in liveVacancyIds) { var vacancy = await _vacancyQuery.GetVacancyAsync(vacancyId); var programme = programmes.Single(p => p.Id == vacancy.ProgrammeId); var vacancyProjection = vacancy.ToVacancyProjectionBase <LiveVacancy>(programme, () => QueryViewType.LiveVacancy.GetIdValue(vacancy.VacancyReference.ToString()), _timeProvider); await _queryStoreWriter.UpdateLiveVacancyAsync(vacancyProjection); } watch.Stop(); _logger.LogInformation("Recreated LiveVacancy projections. Deleted:{deletedCount}. Inserted:{insertedCount}. executionTime:{executionTimeMs}ms", deletedCount, liveVacancyIds.Count, watch.ElapsedMilliseconds); }