Skip to content

Commit

Permalink
Merge branch 'master' into chore/summary/adjust-recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathanio123 authored Aug 21, 2024
2 parents cddb878 + c0cea7e commit 7d95442
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 68 deletions.
1 change: 1 addition & 0 deletions pipelines/templates/deploy-function-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ steps:
queues = @{
provisionPosition = "provision-position"
scheduledNotificationReportQueue = "scheduled-notification"
departmentSummaryWeeklyQueue = "department-summary-weekly-queue"
}
}
Expand Down
3 changes: 1 addition & 2 deletions pipelines/templates/deploy-summary-function-pr-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ steps:
fusion = "${{ parameters.fusionResource }}"
}
queues = @{
provisionPosition = "provision-position"
scheduledNotificationReportQueue = "scheduled-notification"
departmentSummaryWeeklyQueue = "department-summary-weekly-queue"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fusion": "5a842df8-3238-415d-b168-9f16a6a6031b"
},
"queues": {
"departmentSummaryWeeklyQueue": "department-summary-weekly-queue"
}
}
},
Expand Down Expand Up @@ -159,6 +160,10 @@
{
"name": "Endpoints_Resources_Fusion",
"value": "[parameters('settings').resources.fusion]"
},
{
"name": "department_summary_weekly_queue",
"value": "[parameters('settings').queues.departmentSummaryWeeklyQueue]"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Fusion.Resources.Functions.Common.ApiClients;
using Fusion.Resources.Functions.Common.ApiClients.ApiModels;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;

namespace Fusion.Summary.Functions.Functions;

public class DepartmentResourceOwnerSync
{
private readonly ILineOrgApiClient lineOrgApiClient;
private readonly ISummaryApiClient summaryApiClient;
private readonly IConfiguration configuration;

public DepartmentResourceOwnerSync(ILineOrgApiClient lineOrgApiClient, ISummaryApiClient summaryApiClient)
private string _serviceBusConnectionString;
private string _weeklySummaryQueueName;

public DepartmentResourceOwnerSync(
ILineOrgApiClient lineOrgApiClient,
ISummaryApiClient summaryApiClient,
IConfiguration configuration)
{
this.lineOrgApiClient = lineOrgApiClient;
this.summaryApiClient = summaryApiClient;
this.configuration = configuration;
}

/// <summary>
/// Function does two things:
/// - Fetches all departments and updates the database
/// - Sends the department info to the weekly summary queue for the workers to pick up
/// </summary>
/// <param name="timerInfo">The running date & time</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
[FunctionName("department-resource-owner-sync")]
public async Task RunAsync(
[TimerTrigger("0 05 00 * * *", RunOnStartup = false)]
TimerInfo timerInfo, CancellationToken cancellationToken
)
{
_serviceBusConnectionString = configuration["AzureWebJobsServiceBus"];
_weeklySummaryQueueName = configuration["department_summary_weekly_queue"];

var client = new ServiceBusClient(_serviceBusConnectionString);
var sender = client.CreateSender(_weeklySummaryQueueName);

// Fetch all departments
var departments = await lineOrgApiClient.GetOrgUnitDepartmentsAsync();

var selectedDepartments = departments
Expand Down Expand Up @@ -64,7 +92,23 @@ public async Task RunAsync(
await Parallel.ForEachAsync(resourceOwnerDepartments, parallelOptions,
async (ownerDepartment, token) =>
{
// Update the database
await summaryApiClient.PutDepartmentAsync(ownerDepartment, token);

// Send queue message
await SendDepartmentToQueue(sender, ownerDepartment);
});
}

private async Task SendDepartmentToQueue(ServiceBusSender sender, ApiResourceOwnerDepartment department, double delayInMinutes = 0)
{
var serializedDto = JsonConvert.SerializeObject(department);

var message = new ServiceBusMessage(Encoding.UTF8.GetBytes(serializedDto))
{
ScheduledEnqueueTime = DateTime.UtcNow.AddMinutes(delayInMinutes)
};

await sender.SendMessageAsync(message);
}
}
40 changes: 20 additions & 20 deletions src/Fusion.Summary.Functions/Fusion.Summary.Functions.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fusion.Resources.Functions.Common\Fusion.Resources.Functions.Common.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fusion.Resources.Functions.Common\Fusion.Resources.Functions.Common.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fusion.Summary.Functions", "Fusion.Summary.Functions.csproj", "{A7707D46-393A-4CFB-8EF0-9C07F869AAB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A7707D46-393A-4CFB-8EF0-9C07F869AAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7707D46-393A-4CFB-8EF0-9C07F869AAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7707D46-393A-4CFB-8EF0-9C07F869AAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7707D46-393A-4CFB-8EF0-9C07F869AAB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2D189714-F592-4D5E-8842-CDD6131DF283}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"queues": {
"provisionPosition": "provision-position",
"scheduledNotificationReportQueue": "scheduled-notification"

}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="3.1.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Fusion.ApiClients.Org" Version="7.0.0" />
<PackageReference Include="Fusion.Integration" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="3.1.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Fusion.ApiClients.Org" Version="7.0.0" />
<PackageReference Include="Fusion.Integration" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />

<PackageReference Include="Fusion.Events.Azure.Functions.Extensions" Version="6.0.2" />
<PackageReference Include="Fusion.Events.Services" Version="8.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Fusion.Resources.Functions.Common\Fusion.Resources.Functions.Common.csproj" />
<ProjectReference Include="..\..\integration\Fusion.Resources.Integration.Models\Fusion.Resources.Integration.Models.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.template.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Fusion.Resources.Functions.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<PackageReference Include="Fusion.Events.Azure.Functions.Extensions" Version="6.0.2" />
<PackageReference Include="Fusion.Events.Services" Version="8.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Fusion.Resources.Functions.Common\Fusion.Resources.Functions.Common.csproj" />
<ProjectReference Include="..\..\integration\Fusion.Resources.Integration.Models\Fusion.Resources.Integration.Models.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.template.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Fusion.Resources.Functions.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"provision_position_queue": "provision-position-[REPLACE WITH DEV QUEUE]",
"scheduled_notification_report_queue": "scheduled-notification-[REPLACE WITH DEV QUEUE]",
"department_summary_weekly_queue": "department-summary-weekly-queue-[REPLACE WITH DEV QUEUE]",
"AzureWebJobsServiceBus": "[REPLACE WITH SB CONNECTION STRING]",
"AzureAd_TenantId": "3aa4a235-b6e2-48d5-9195-7fcf05b459b0",
"AzureAd_ClientId": "5a842df8-3238-415d-b168-9f16a6a6031b",
Expand Down

0 comments on commit 7d95442

Please sign in to comment.