diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs index 3447fb4213..8c2b6ec391 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs @@ -25,7 +25,6 @@ using SFA.DAS.EmployerAccounts.Queries.GetReservations; using SFA.DAS.EmployerAccounts.Queries.GetTeamUser; using SFA.DAS.EmployerAccounts.Queries.GetUserAccountRole; -using SFA.DAS.EmployerAccounts.Web.Extensions; using SFA.DAS.EmployerAccounts.Queries.GetVacancies; using SFA.DAS.EmployerAccounts.Web.Orchestrators; using SFA.DAS.EmployerAccounts.Web.ViewModels; diff --git a/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs b/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs index 762376fcfc..c2ae844951 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs @@ -36,7 +36,6 @@ using SFA.DAS.EmployerAccounts.Models.Recruit; using ResourceNotFoundException = SFA.DAS.EmployerAccounts.Web.Exceptions.ResourceNotFoundException; using SFA.DAS.Common.Domain.Types; -using SFA.DAS.EmployerAccounts.Configuration; namespace SFA.DAS.EmployerAccounts.Web.Orchestrators { @@ -45,26 +44,18 @@ public class EmployerTeamOrchestrator : UserVerificationOrchestratorBase private readonly IMediator _mediator; private readonly ICurrentDateTime _currentDateTime; private readonly IAccountApiClient _accountApiClient; - private readonly IMapper _mapper; - private EmployerApprenticeshipsServiceConfiguration _employerApprenticeshipsServiceConfiguration; - + private readonly IMapper _mapper; + public EmployerTeamOrchestrator(IMediator mediator, ICurrentDateTime currentDateTime, IAccountApiClient accountApiClient, - IMapper mapper, EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration) + IMapper mapper) : base(mediator) { _mediator = mediator; _currentDateTime = currentDateTime; _accountApiClient = accountApiClient; - _mapper = mapper; - _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration; - } - - //Needed for tests - protected EmployerTeamOrchestrator(EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration) - { - _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration; + _mapper = mapper; } public async Task> Cancel(string email, string hashedAccountId, string externalUserId) @@ -159,7 +150,6 @@ public virtual async Task> GetAc { try { - var timeout = _employerApprenticeshipsServiceConfiguration.AddApprenticeCallToActionTimeout; var apiGetAccountTask = _accountApiClient.GetAccount(hashedAccountId); var accountResponseTask = _mediator.SendAsync(new GetEmployerAccountByHashedIdQuery @@ -191,15 +181,13 @@ public virtual async Task> GetAc var reservationsResponseTask = _mediator.SendAsync(new GetReservationsRequest { HashedAccountId = hashedAccountId, - ExternalUserId = externalUserId, - TimeOut = timeout + ExternalUserId = externalUserId }); var apprenticeshipsResponseTask = _mediator.SendAsync(new GetApprenticeshipsRequest { HashedAccountId = hashedAccountId, - ExternalUserId = externalUserId, - TimeOut = timeout + ExternalUserId = externalUserId }); var accountCohortResponseTask = _mediator.SendAsync(new GetSingleCohortRequest @@ -211,8 +199,7 @@ public virtual async Task> GetAc var vacanciesResponseTask = _mediator.SendAsync(new GetVacanciesRequest { HashedAccountId = hashedAccountId, - ExternalUserId = externalUserId, - TimeOut = timeout + ExternalUserId = externalUserId }); await Task.WhenAll(apiGetAccountTask, accountStatsResponseTask, userRoleResponseTask, userResponseTask, accountStatsResponseTask, agreementsResponseTask, reservationsResponseTask, apprenticeshipsResponseTask, accountCohortResponseTask, vacanciesResponseTask).ConfigureAwait(false); diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs index f7549a381c..0e0a79cbde 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs @@ -1,6 +1,7 @@ using System; using MediatR; using System.Threading.Tasks; +using SFA.DAS.EmployerAccounts.Configuration; using SFA.DAS.NLog.Logger; using SFA.DAS.Validation; using SFA.DAS.EmployerAccounts.Interfaces; @@ -15,17 +16,18 @@ public class GetApprenticeshipsHandler : IAsyncRequestHandler validator, ILog logger, ICommitmentV2Service commitmentV2Service, - IHashingService hashingService) + IHashingService hashingService, EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration) { _validator = validator; _logger = logger; _commitmentV2Service = commitmentV2Service; _hashingService = hashingService; + _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration; } public async Task Handle(GetApprenticeshipsRequest message) diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequest.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequest.cs index 8bc9014c39..34b6bc8459 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequest.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequest.cs @@ -6,6 +6,5 @@ public class GetReservationsRequest : IAsyncRequest { public string HashedAccountId { get; set; } public string ExternalUserId { get; set; } - public int TimeOut { get; set; } } } diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequestHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequestHandler.cs index 69c6ac52de..bebf268fc4 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequestHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetReservations/GetReservationsRequestHandler.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using MediatR; +using SFA.DAS.EmployerAccounts.Configuration; using SFA.DAS.EmployerAccounts.Interfaces; using SFA.DAS.HashingService; using SFA.DAS.NLog.Logger; @@ -14,17 +15,20 @@ public class GetReservationsRequestHandler : IAsyncRequestHandler validator, ILog logger, IReservationsService service, - IHashingService hashingService) + IHashingService hashingService, + EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration) { _validator = validator; _logger = logger; _service = service; _hashingService = hashingService; + _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration; } public async Task Handle(GetReservationsRequest message) @@ -43,7 +47,7 @@ public async Task Handle(GetReservationsRequest message try { var task = _service.Get(accountId); - if (await Task.WhenAny(task, Task.Delay(message.TimeOut)) == task) + if (await Task.WhenAny(task, Task.Delay(_employerApprenticeshipsServiceConfiguration.AddApprenticeCallToActionTimeout)) == task) { await task; } @@ -54,7 +58,7 @@ public async Task Handle(GetReservationsRequest message } catch (TimeoutException ex) { - _logger.Error(ex, $"Failued to get Reservations for {message.HashedAccountId}"); + _logger.Error(ex, $"Failed to get Reservations for {message.HashedAccountId}"); return new GetReservationsResponse { HasFailed = true diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs index 518ca96981..b3af3a02ae 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs @@ -3,6 +3,7 @@ using SFA.DAS.Validation; using SFA.DAS.EmployerAccounts.Interfaces; using System.Linq; +using SFA.DAS.EmployerAccounts.Configuration; using SFA.DAS.HashingService; using System; using SFA.DAS.NLog.Logger; diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequest.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequest.cs index 3b21f70274..4f75907a55 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequest.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequest.cs @@ -6,6 +6,5 @@ public class GetVacanciesRequest : IAsyncRequest { public string HashedAccountId { get; set; } public string ExternalUserId { get; set; } - public int TimeOut { get; set; } } } diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequestHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequestHandler.cs index 4ccef1fecb..47685c970f 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequestHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetVacancies/GetVacanciesRequestHandler.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using MediatR; +using SFA.DAS.EmployerAccounts.Configuration; using SFA.DAS.EmployerAccounts.Interfaces; using SFA.DAS.NLog.Logger; using SFA.DAS.Validation; @@ -12,15 +13,17 @@ public class GetVacanciesRequestHandler : IAsyncRequestHandler _validator; private readonly ILog _logger; private readonly IRecruitService _service; + private readonly EmployerApprenticeshipsServiceConfiguration _employerApprenticeshipsServiceConfiguration; public GetVacanciesRequestHandler( IValidator validator, ILog logger, - IRecruitService service) + IRecruitService service, EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration) { _validator = validator; _logger = logger; _service = service; + _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration; } public async Task Handle(GetVacanciesRequest message) @@ -37,23 +40,28 @@ public async Task Handle(GetVacanciesRequest message) try { var task = _service.GetVacancies(message.HashedAccountId); - if (await Task.WhenAny(task, Task.Delay(message.TimeOut)) == task) + if (await Task.WhenAny(task, Task.Delay(_employerApprenticeshipsServiceConfiguration.AddApprenticeCallToActionTimeout)) == task) { await task; - } - else - { return new GetVacanciesResponse { - HasFailed = true + Vacancies = task.Result }; } return new GetVacanciesResponse { - Vacancies = task.Result + HasFailed = true + }; + } + catch (TimeoutException ex) + { + _logger.Error(ex, $"Failed to get Reservations for {message.HashedAccountId}"); + return new GetVacanciesResponse + { + HasFailed = true }; } - catch(Exception ex) + catch (Exception ex) { _logger.Error(ex, $"Failed to get vacancies for {message.HashedAccountId}"); return new GetVacanciesResponse