public async Task SendIlrSubmissionEvent(long ukprn, short collectionYear, byte collectionPeriod, long jobId, bool success) { try { dataContext.ClearJobId(jobId); var subscriptionName = DcConfiguration.SubscriptionName; var dto = new JobContextDto { JobId = jobId, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.UkPrn, ukprn }, { JobContextMessageKey.CollectionYear, collectionYear }, { JobContextMessageKey.ReturnPeriod, collectionPeriod }, { JobContextMessageKey.Username, "PV2-Automated" } }, SubmissionDateTimeUtc = DateTime.UtcNow, TopicPointer = 0, Topics = new List <TopicItemDto> { new TopicItemDto { SubscriptionName = subscriptionName, Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string> { success?"JobSuccess":"JobFailure" } } } } } }; await topicPublishingService.PublishAsync(dto, new Dictionary <string, object> { { "To", "GenerateFM36Payments" } }, "GenerateFM36Payments"); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task SendPeriodEndTask(short collectionYear, byte collectionPeriod, long jobId, string taskName) { try { dataContext.ClearJobId(jobId); var dto = new JobContextDto { JobId = jobId, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.UkPrn, 0 }, { JobContextMessageKey.Filename, string.Empty }, { JobContextMessageKey.CollectionYear, collectionYear }, { JobContextMessageKey.ReturnPeriod, collectionPeriod }, { JobContextMessageKey.Username, "PV2-Automated" } }, SubmissionDateTimeUtc = DateTime.UtcNow, TopicPointer = 0, Topics = new List <TopicItemDto> { new TopicItemDto { SubscriptionName = "Payments", Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string> { taskName } } } } } }; await topicPublishingService.PublishAsync(dto, new Dictionary <string, object> { { "To", "Payments" } }, $"Payments_{taskName}"); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task SendPeriodEndTask(short academicYear, byte collectionPeriod, long jobId, PeriodEndTask periodEndTask) { try { var dto = new JobContextDto { JobId = jobId, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.UkPrn, 0 }, { JobContextMessageKey.Filename, string.Empty }, { JobContextMessageKey.CollectionName, $"PE-DAS-{periodEndTask:G}{academicYear}" }, { JobContextMessageKey.CollectionYear, academicYear }, { JobContextMessageKey.ReturnPeriod, collectionPeriod }, { JobContextMessageKey.Username, "Period End" } }, SubmissionDateTimeUtc = DateTime.UtcNow, TopicPointer = 0, Topics = new List <TopicItemDto> { new TopicItemDto { SubscriptionName = "Payments", Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string> { periodEndTask.ToString("G") } } } } } }; var publisher = topicPublishingServiceFactory.GetPeriodEndTaskPublisher(periodEndTask); await publisher.PublishAsync(dto, new Dictionary <string, object> { { "To", "Payments" } }, "Payments"); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void TestJobContextMappingDtoToInterface() { DateTime now = DateTime.UtcNow; JobContextDto jobContextDto = new JobContextDto { SubmissionDateTimeUtc = now, JobId = 12, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.UkPrn, 12345 } }, TopicPointer = 3, Topics = new List <TopicItemDto> { new TopicItemDto { Tasks = new List <TaskItemDto> { new TaskItemDto { Tasks = new List <string> { "Task A" }, SupportsParallelExecution = true } }, SubscriptionName = "Subscription A" } } }; JobContextMapper mapper = new JobContextMapper(); JobContextMessage message = mapper.MapTo(jobContextDto); message.SubmissionDateTimeUtc.Should().Be(now); message.JobId.Should().Be(12); message.KeyValuePairs.Should().BeEquivalentTo(jobContextDto.KeyValuePairs); message.Topics.Should().BeEquivalentTo(jobContextDto.Topics); message.TopicPointer.Should().Be(3); }
public void TestJobContextMappingInterfaceToDto() { DateTime now = DateTime.UtcNow; List <ITaskItem> tasks = new List <ITaskItem>() { new TaskItem { Tasks = new List <string> { "Task A" }, SupportsParallelExecution = true } }; var topicItem = new TopicItem("Topic A", "SqlFilter A", tasks); JobContextMessage jobContextMessage = new JobContextMessage { JobId = 12, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.UkPrn, 12345 } }, SubmissionDateTimeUtc = now, TopicPointer = 3, Topics = new List <ITopicItem> { topicItem } }; JobContextMapper mapper = new JobContextMapper(); JobContextDto dto = mapper.MapFrom(jobContextMessage); dto.SubmissionDateTimeUtc.Should().Be(now); dto.JobId.Should().Be(12); dto.KeyValuePairs.Should().BeEquivalentTo(jobContextMessage.KeyValuePairs); dto.Topics.Should().BeEquivalentTo(jobContextMessage.Topics); dto.TopicPointer.Should().Be(3); }
public async Task SendIlrSubmission(List <FM36Learner> learners, long ukprn, short collectionYear, byte collectionPeriod, long jobId) { try { dataContext.ClearJobId(jobId); var messagePointer = Guid.NewGuid().ToString().Replace("-", string.Empty); var ilrSubmission = new FM36Global { UKPRN = (int)ukprn, Year = collectionYear.ToString(), Learners = learners }; var json = serializationService.Serialize(ilrSubmission); var storageContainer = DcConfiguration.DcBlobStorageContainer; var subscriptionName = DcConfiguration.SubscriptionName; using (var stream = await azureFileService.OpenWriteStreamAsync(messagePointer, storageContainer, new CancellationToken())) using (var writer = new StreamWriter(stream)) { await writer.WriteAsync(json); } var dto = new JobContextDto { JobId = jobId, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.FundingFm36Output, messagePointer }, { JobContextMessageKey.Filename, messagePointer }, { JobContextMessageKey.UkPrn, ukprn }, { JobContextMessageKey.Container, storageContainer }, { JobContextMessageKey.ReturnPeriod, collectionPeriod }, { JobContextMessageKey.Username, "PV2-Automated" } }, SubmissionDateTimeUtc = DateTime.UtcNow, TopicPointer = 0, Topics = new List <TopicItemDto> { new TopicItemDto { SubscriptionName = subscriptionName, Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string>() } } } } }; await topicPublishingService.PublishAsync(dto, new Dictionary <string, object> { { "To", "GenerateFM36Payments" } }, "GenerateFM36Payments"); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task SendIlrSubmissionEvent(long ukprn, short collectionYear, byte collectionPeriod, long jobId, bool success) { try { //dataContext.ClearJobId(jobId); //TODO: Not sure why we'd remove the job before confirming it var subscriptionName = DcConfiguration.SubscriptionName; var messagePointer = Guid.NewGuid().ToString().Replace("-", string.Empty); var dto = new JobContextDto { JobId = jobId, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.Filename, messagePointer }, { JobContextMessageKey.FundingFm36Output, messagePointer }, { JobContextMessageKey.UkPrn, ukprn }, { JobContextMessageKey.CollectionYear, collectionYear }, { JobContextMessageKey.ReturnPeriod, collectionPeriod }, { JobContextMessageKey.Username, "PV2-Automated" } }, SubmissionDateTimeUtc = DateTime.UtcNow, TopicPointer = 1, Topics = new List <TopicItemDto> { new TopicItemDto { SubscriptionName = subscriptionName, Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string>() } } }, new TopicItemDto { SubscriptionName = subscriptionName, Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string> { success?"JobSuccess":"JobFailure" } } } } } }; var topicPublishingService = topicPublishingServiceFactory.GetSubmissionPublisher(); await topicPublishingService.PublishAsync(dto, new Dictionary <string, object> { { "To", "GenerateFM36Payments" } }, "GenerateFM36Payments"); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task SubmitFM36(string fm36Json, long ukprn, short academicYear, byte collectionPeriod, long jobId) { try { var container = $"ilr{academicYear}-files"; var messagePointer = $"{ukprn}/{jobId}/FundingFm36Output.json"; using (var stream = await azureFileService.OpenWriteStreamAsync(messagePointer, container, new CancellationToken())) using (var writer = new StreamWriter(stream)) { await writer.WriteAsync(fm36Json); } var dto = new JobContextDto { JobId = jobId, KeyValuePairs = new Dictionary <string, object> { { JobContextMessageKey.CollectionYear, academicYear }, { JobContextMessageKey.FundingFm36Output, messagePointer }, { JobContextMessageKey.Filename, messagePointer }, { JobContextMessageKey.UkPrn, ukprn }, { JobContextMessageKey.Container, container }, { JobContextMessageKey.ReturnPeriod, collectionPeriod }, { JobContextMessageKey.Username, "PV2-Automated" } }, SubmissionDateTimeUtc = DateTime.UtcNow, TopicPointer = 0, Topics = new List <TopicItemDto> { new TopicItemDto { SubscriptionName = "GenerateFM36Payments", Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string>() } } } } }; var publisher = topicPublishingServiceFactory.GetSubmissionPublisher(academicYear); await publisher.PublishAsync(dto, new Dictionary <string, object> { { "To", "GenerateFM36Payments" } }, "GenerateFM36Payments"); await Task.Delay(500); dto.Topics.Add(new TopicItemDto { SubscriptionName = "GenerateFM36Payments", Tasks = new List <TaskItemDto> { new TaskItemDto { SupportsParallelExecution = false, Tasks = new List <string> { "JobSuccess" } } } }); dto.TopicPointer = 1; await publisher.PublishAsync(dto, new Dictionary <string, object> { { "To", "GenerateFM36Payments" } }, "GenerateFM36Payments"); } catch (Exception e) { Console.WriteLine(e); throw; } }