Skip to content

Commit

Permalink
CON-1640-make code review comment changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
shomavg committed Apr 21, 2020
1 parent 77dcb2a commit ea7d6a4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<OrchestratorResponse<EmployerTeamMembersViewModel>> Cancel(string email, string hashedAccountId, string externalUserId)
Expand Down Expand Up @@ -159,7 +150,6 @@ public virtual async Task<OrchestratorResponse<AccountDashboardViewModel>> GetAc
{
try
{
var timeout = _employerApprenticeshipsServiceConfiguration.AddApprenticeCallToActionTimeout;
var apiGetAccountTask = _accountApiClient.GetAccount(hashedAccountId);

var accountResponseTask = _mediator.SendAsync(new GetEmployerAccountByHashedIdQuery
Expand Down Expand Up @@ -191,15 +181,13 @@ public virtual async Task<OrchestratorResponse<AccountDashboardViewModel>> 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
Expand All @@ -211,8 +199,7 @@ public virtual async Task<OrchestratorResponse<AccountDashboardViewModel>> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,17 +16,18 @@ public class GetApprenticeshipsHandler : IAsyncRequestHandler<GetApprenticeships
private readonly ILog _logger;
private readonly ICommitmentV2Service _commitmentV2Service;
private readonly IHashingService _hashingService;

private readonly EmployerApprenticeshipsServiceConfiguration _employerApprenticeshipsServiceConfiguration;
public GetApprenticeshipsHandler(
IValidator<GetApprenticeshipsRequest> validator,
ILog logger,
ICommitmentV2Service commitmentV2Service,
IHashingService hashingService)
IHashingService hashingService, EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration)
{
_validator = validator;
_logger = logger;
_commitmentV2Service = commitmentV2Service;
_hashingService = hashingService;
_employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration;
}

public async Task<GetApprenticeshipsResponse> Handle(GetApprenticeshipsRequest message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ public class GetReservationsRequest : IAsyncRequest<GetReservationsResponse>
{
public string HashedAccountId { get; set; }
public string ExternalUserId { get; set; }
public int TimeOut { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,17 +15,20 @@ public class GetReservationsRequestHandler : IAsyncRequestHandler<GetReservation
private readonly ILog _logger;
private readonly IReservationsService _service;
private readonly IHashingService _hashingService;
private readonly EmployerApprenticeshipsServiceConfiguration _employerApprenticeshipsServiceConfiguration;

public GetReservationsRequestHandler(
IValidator<GetReservationsRequest> validator,
ILog logger,
IReservationsService service,
IHashingService hashingService)
IHashingService hashingService,
EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration)
{
_validator = validator;
_logger = logger;
_service = service;
_hashingService = hashingService;
_employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration;
}

public async Task<GetReservationsResponse> Handle(GetReservationsRequest message)
Expand All @@ -43,7 +47,7 @@ public async Task<GetReservationsResponse> 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;
}
Expand All @@ -54,7 +58,7 @@ public async Task<GetReservationsResponse> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ public class GetVacanciesRequest : IAsyncRequest<GetVacanciesResponse>
{
public string HashedAccountId { get; set; }
public string ExternalUserId { get; set; }
public int TimeOut { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,15 +13,17 @@ public class GetVacanciesRequestHandler : IAsyncRequestHandler<GetVacanciesReque
private readonly IValidator<GetVacanciesRequest> _validator;
private readonly ILog _logger;
private readonly IRecruitService _service;
private readonly EmployerApprenticeshipsServiceConfiguration _employerApprenticeshipsServiceConfiguration;

public GetVacanciesRequestHandler(
IValidator<GetVacanciesRequest> validator,
ILog logger,
IRecruitService service)
IRecruitService service, EmployerApprenticeshipsServiceConfiguration employerApprenticeshipsServiceConfiguration)
{
_validator = validator;
_logger = logger;
_service = service;
_employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration;
}

public async Task<GetVacanciesResponse> Handle(GetVacanciesRequest message)
Expand All @@ -37,23 +40,28 @@ public async Task<GetVacanciesResponse> 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
Expand Down

0 comments on commit ea7d6a4

Please sign in to comment.