-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CON-1185 Implements data migration for ALE Id
- Loading branch information
dev4valtech
committed
Dec 17, 2019
1 parent
4e519dc
commit 6bf08d6
Showing
7 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/Jobs/Recruit.Vacancies.Jobs/Triggers/QueueTriggers/BeginMigrationQueueTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Esfa.Recruit.Vacancies.Client.Application.Queues; | ||
using Esfa.Recruit.Vacancies.Client.Application.Queues.Messages; | ||
using Esfa.Recruit.Vacancies.Client.Domain.Repositories; | ||
using Esfa.Recruit.Vacancies.Client.Infrastructure.StorageQueue; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Esfa.Recruit.Vacancies.Jobs.Triggers.QueueTriggers | ||
{ | ||
public class BeginMigrationQueueTrigger | ||
{ | ||
private readonly IVacancyQuery _vacancyQuery; | ||
private readonly IRecruitQueueService _recruitQueueService; | ||
private readonly ILogger<BeginMigrationQueueTrigger> _logger; | ||
public BeginMigrationQueueTrigger( | ||
IVacancyQuery vacancyQuery, | ||
IRecruitQueueService recruitQueueService, | ||
ILogger<BeginMigrationQueueTrigger> logger) | ||
{ | ||
_vacancyQuery = vacancyQuery; | ||
_recruitQueueService = recruitQueueService; | ||
_logger = logger; | ||
} | ||
|
||
public async Task BeginMigrationAsync( | ||
[QueueTrigger(QueueNames.BeginMigrationQueueName, Connection = "QueueStorage")] string message, | ||
TextWriter log) | ||
{ | ||
await RunVacancyALEIdMigrationAsync(); | ||
} | ||
|
||
private async Task RunVacancyALEIdMigrationAsync() | ||
{ | ||
_logger.LogInformation("Begining queuing vacancies for ALE Id migration process"); | ||
var tasks = new List<Task>(); | ||
var vacancyIds = await _vacancyQuery.GetAllVacancyIdsAsync(); | ||
_logger.LogInformation($"Found {vacancyIds.Count()} vacancies for ALE Id migration"); | ||
foreach (var vacancyId in vacancyIds) | ||
tasks.Add(SendVacancyALEIdMigrationMessage(vacancyId)); | ||
await Task.WhenAll(tasks); | ||
} | ||
|
||
private Task SendVacancyALEIdMigrationMessage(Guid vacancyId) | ||
{ | ||
_logger.LogInformation($"Queueing up vacancy {vacancyId} for ALE Id migration"); | ||
var message = new DataMigrationQueueMessage {VacancyId = vacancyId}; | ||
return _recruitQueueService.AddMessageAsync<DataMigrationQueueMessage>(message); | ||
} | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/Jobs/Recruit.Vacancies.Jobs/Triggers/QueueTriggers/PerformDataMigrationQueueTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Esfa.Recruit.Vacancies.Client.Application.Queues.Messages; | ||
using Esfa.Recruit.Vacancies.Client.Domain.Repositories; | ||
using Esfa.Recruit.Vacancies.Client.Infrastructure.Services.EmployerAccount; | ||
using Esfa.Recruit.Vacancies.Client.Infrastructure.StorageQueue; | ||
using Microsoft.Azure.WebJobs; | ||
using System.Linq; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Esfa.Recruit.Vacancies.Jobs.Triggers.QueueTriggers | ||
{ | ||
public class PerformDataMigrationQueueTrigger | ||
{ | ||
private readonly IVacancyRepository _vacancyRepository; | ||
private readonly IEmployerAccountProvider _employerAccountProvider; | ||
private readonly ILogger<PerformDataMigrationQueueTrigger> _logger; | ||
public PerformDataMigrationQueueTrigger( | ||
IVacancyRepository vacancyRepository, | ||
IEmployerAccountProvider employerAccountProvider, | ||
ILogger<PerformDataMigrationQueueTrigger> logger) | ||
{ | ||
_vacancyRepository = vacancyRepository; | ||
_employerAccountProvider = employerAccountProvider; | ||
_logger = logger; | ||
} | ||
|
||
public async Task ExecuteAsync( | ||
[QueueTrigger(QueueNames.DataMigrationQueueName, Connection = "QueueStorage")] DataMigrationQueueMessage message, | ||
TextWriter log) | ||
{ | ||
await PerformVacancyALEIdMigration(message); | ||
} | ||
|
||
private async Task PerformVacancyALEIdMigration(DataMigrationQueueMessage message) | ||
{ | ||
var vacancy = await _vacancyRepository.GetVacancyAsync(message.VacancyId); | ||
if (vacancy == null || vacancy.LegalEntityId == 0 || string.IsNullOrWhiteSpace(vacancy.AccountLegalEntityPublicHashedId) == false) | ||
{ | ||
_logger.LogWarning($"Bypassing vacancy {message.VacancyId}"); | ||
return; | ||
} | ||
var legalEntities = await _employerAccountProvider.GetLegalEntitiesConnectedToAccountAsync(vacancy.EmployerAccountId); | ||
var selectedLegalEntity = legalEntities.FirstOrDefault(l => l.LegalEntityId == vacancy.LegalEntityId); | ||
if (selectedLegalEntity == null) | ||
{ | ||
_logger.LogError($"Unable to find legal entity for vacancy {message.VacancyId}"); | ||
return; | ||
} | ||
_logger.LogInformation($"Updating vacancy: {vacancy.Id} setting AccountLegalEntityPublicHashedId: {selectedLegalEntity.AccountLegalEntityPublicHashedId}"); | ||
vacancy.AccountLegalEntityPublicHashedId = selectedLegalEntity.AccountLegalEntityPublicHashedId; | ||
await _vacancyRepository.UpdateAsync(vacancy); | ||
_logger.LogInformation($"Successfully updated vacancy: {vacancy.Id} with AccountLegalEntityPublicHashedId: {selectedLegalEntity.AccountLegalEntityPublicHashedId}"); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Shared/Recruit.Vacancies.Client/Application/Queues/Messages/DataMigrationQueueMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace Esfa.Recruit.Vacancies.Client.Application.Queues.Messages | ||
{ | ||
public class DataMigrationQueueMessage | ||
{ | ||
public Guid VacancyId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters