private async Task CreateClosedVacancyProjection(Guid vacancyId)
        {
            var vacancyTask   = _repository.GetVacancyAsync(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);

            await _queryStore.UpdateClosedVacancyAsync(vacancy.ToVacancyProjectionBase <ClosedVacancy>(programme, () => QueryViewType.ClosedVacancy.GetIdValue(vacancy.VacancyReference.ToString())));
        }
Example #2
0
        private async Task CreateClosedVacancyProjection(Guid vacancyId)
        {
            var vacancyTask   = _repository.GetVacancyAsync(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);

            await _queryStore.UpdateClosedVacancyAsync(vacancy.ToVacancyProjectionBase <ClosedVacancy>(programme, () => QueryViewType.ClosedVacancy.GetIdValue(vacancy.VacancyReference.ToString()), _timeProvider));

            if (vacancy.ClosureReason == ClosureReason.WithdrawnByQa)
            {
                _logger.LogInformation($"Queuing up withdrawn notification message for vacancy {vacancy.VacancyReference}");
                var communicationRequest = GetVacancyWithdrawnByQaCommunicationRequest(vacancy.VacancyReference.Value);
                await _communicationQueueService.AddMessageAsync(communicationRequest);
            }
        }
        private async Task RegenerateClosedVacancies(List <Guid> closedVacancyIds, List <ApprenticeshipProgramme> programmes)
        {
            var watch = Stopwatch.StartNew();

            var deletedCount = await _queryStoreWriter.DeleteAllClosedVacancies();

            foreach (var vacancyId in closedVacancyIds)
            {
                var vacancy = await _vacancyQuery.GetVacancyAsync(vacancyId);

                var programme         = programmes.Single(p => p.Id == vacancy.ProgrammeId);
                var vacancyProjection = vacancy.ToVacancyProjectionBase <ClosedVacancy>(programme,
                                                                                        () => QueryViewType.ClosedVacancy.GetIdValue(vacancy.VacancyReference.ToString()), _timeProvider);

                await _queryStoreWriter.UpdateClosedVacancyAsync(vacancyProjection);
            }

            watch.Stop();

            _logger.LogInformation("Recreated ClosedVacancy projections. Deleted:{deletedCount}. Inserted:{insertedCount}. executionTime:{executionTimeMs}ms", deletedCount, closedVacancyIds.Count, watch.ElapsedMilliseconds);
        }