Skip to content

Commit 82c6485

Browse files
feat: adding simple service bus function for create exception (#1145)
* feat: migrate to service bus * feat: service bus migration * feat: adding simple service buss fucntion for create exception * feat: new functions * feat: distribute participant * feat: queue name switch * revert changes * fix: update name * Update Program.cs * fix: tests * fix: tests * feat: adding new service bus function for create exception * adding new function to compose * fix: making sure create exception is in a durrable function Signed-off-by: SamRobinson75684 <[email protected]> * fix: sonarqube issues * chore: removing unwanted imports * fix: adding the use UseNewFunctions to tf vars * chore: exention does not now use any input params * fix: calling the FetchDataActivity in the DistributeParticipant function code * chore: addressing comments * chore: addressing comments * fix: remvong required tag on new ServiceBusConnectionString in RCF * chore: addressing sonar cube isues and code review comments * fix: fixing unit tests * fix: adding config values to create-exception * adressing merge conflicts * fix: fixing unit tests * fix: fixing unit tests * fix: fixing unit tests * fix: fixing unit tests * fix: fixing unit tests * fix: trying to fix unit tests * fix: trying to fix unit tests * fix: verifying that Update is never called from the _mockParticipantDemographicClient * fix: fixing unit tests * fix: fixing unit tests * fix: removing the durrable ascept of the new create exception function * fix: removing merge problem * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * fix: addressing comments * using the corect dotnet runtimes for create expception --------- Signed-off-by: SamRobinson75684 <[email protected]> Co-authored-by: will-larkin <[email protected]>
1 parent 828d7a6 commit 82c6485

File tree

15 files changed

+226
-14
lines changed

15 files changed

+226
-14
lines changed

application/CohortManager/Set-up/service-bus/config.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@
3232
"RequiresSession": false
3333
}
3434
}
35+
],
36+
"Topics": [
37+
{
38+
"Name": "createExceptionTopic",
39+
"Properties": {
40+
"DefaultMessageTimeToLive": "PT1H",
41+
"DuplicateDetectionHistoryTimeWindow": "PT20S",
42+
"RequiresDuplicateDetection": false
43+
},
44+
"Subscriptions": [
45+
{
46+
"Name": "exceptionSub",
47+
"Properties": {
48+
"DeadLetteringOnMessageExpiration": false,
49+
"DefaultMessageTimeToLive": "PT1H",
50+
"LockDuration": "PT1M",
51+
"MaxDeliveryCount": 10,
52+
"ForwardDeadLetteredMessagesTo": "",
53+
"ForwardTo": "",
54+
"RequiresSession": false
55+
}
56+
}
57+
]
58+
}
3559
]
3660
}
3761
],

application/CohortManager/compose.core.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ services:
220220
- ExceptionManagementDataServiceURL=http://exception-management-data-service:7911/api/ExceptionManagementDataService/
221221
- GPPracticeDataServiceURL=http://localhost:7999/api/GPPracticeDataService/
222222

223+
exception-creation:
224+
container_name: create-exception
225+
image: cohort-manager-create-exception
226+
networks: [cohman-network]
227+
build:
228+
context: ./src/Functions/
229+
dockerfile: ExceptionHandling/ExceptionCreation/Dockerfile
230+
environment:
231+
- ASPNETCORE_URLS=http://*:7070
232+
- ExceptionTopic="createExceptionTopic"
233+
- ExceptionSubscription="exceptionSub"
234+
- ServiceBusConnectionString="Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true"
235+
236+
223237
update-exception:
224238
container_name: update-exception
225239
image: cohort-manager-update-exception

application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateException.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace NHS.CohortManager.ExceptionService;
99
using Model;
1010
using Common;
1111
using Data.Database;
12-
using DataServices.Client;
1312

1413
public class CreateException
1514
{

application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateException.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
1212
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
13+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
1314
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.4" />
14-
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
1515
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.3" />
16+
<PackageReference Include="Microsoft.AspNetCore.App" />
17+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.18.0" />
18+
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
1619
</ItemGroup>
1720
<ItemGroup>
1821
<None Update="host.json">

application/CohortManager/src/Functions/ExceptionHandling/CreateException/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
.AddDataService<ExceptionManagement>(config.ExceptionManagementDataServiceURL)
1414
.AddDataService<ParticipantDemographic>(config.DemographicDataServiceURL)
1515
.Build()
16-
.ConfigureFunctionsWorkerDefaults()
16+
.ConfigureFunctionsWebApplication()
1717
.ConfigureServices(services =>
1818
{
1919
services.AddTransient<IValidationExceptionData, ValidationExceptionData>();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NHS.CohortManager.ExceptionService;
2+
3+
using Microsoft.Azure.Functions.Worker;
4+
using Azure.Messaging.ServiceBus;
5+
6+
public class CreateException
7+
{
8+
[Function("RunCreateException")]
9+
public async Task Run(
10+
[ServiceBusTrigger(topicName: "%ExceptionTopic%", subscriptionName: "%ExceptionSubscription%", Connection = "ServiceBusConnectionString", AutoCompleteMessages = false)]
11+
ServiceBusReceivedMessage message,
12+
ServiceBusMessageActions messageActions)
13+
{
14+
await messageActions.CompleteMessageAsync(message);
15+
}
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<ProjectGuid>{6DD9FFBC-738A-4B07-BCD6-7435B97701B2}</ProjectGuid>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
6+
<OutputType>Exe</OutputType>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
12+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
13+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
14+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.4" />
15+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.3" />
16+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
17+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.18.0" />
18+
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<None Update="host.json">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
24+
<None Update="local.settings.json">
25+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
26+
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
27+
</None>
28+
</ItemGroup>
29+
<ItemGroup>
30+
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
31+
</ItemGroup>
32+
<ItemGroup>
33+
<ProjectReference Include="..\..\Shared\Common\Common.csproj" />
34+
<ProjectReference Include="..\..\Shared\Data\Data.csproj" />
35+
<ProjectReference Include="..\..\Shared\HealthChecks\HealthChecks.csproj" />
36+
<ProjectReference Include="..\..\Shared\Model\Model.csproj" />
37+
</ItemGroup>
38+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace NHS.Screening.CreateException;
2+
3+
using System.ComponentModel.DataAnnotations;
4+
5+
public class CreateExceptionConfig
6+
{
7+
[Required]
8+
public string ExceptionManagementDataServiceURL {get; set;}
9+
[Required]
10+
public string DemographicDataServiceURL {get; set;}
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS base
2+
3+
COPY ./Shared /Shared
4+
WORKDIR /Shared
5+
6+
RUN mkdir -p /home/site/wwwroot && \
7+
dotnet publish ./Common/Common.csproj --output /home/site/wwwroot && \
8+
dotnet publish ./Model/Model.csproj --output /home/site/wwwroot && \
9+
dotnet publish ./Data/Data.csproj --output /home/site/wwwroot && \
10+
dotnet publish ./Utilities/Utilities.csproj --output /home/site/wwwroot && \
11+
dotnet publish ./DataServices.Client/DataServices.Client.csproj --output /home/site/wwwroot && \
12+
dotnet publish ./DataServices.Core/DataServices.Core.csproj --output /home/site/wwwroot && \
13+
dotnet publish ./DataServices.Database/DataServices.Database.csproj --output /home/site/wwwroot
14+
15+
FROM base AS function
16+
17+
COPY ./ExceptionHandling/CreateException /src/dotnet-function-app
18+
WORKDIR /src/dotnet-function-app
19+
20+
RUN --mount=type=cache,target=/root/.nuget/packages \
21+
dotnet publish *.csproj --output /home/site/wwwroot
22+
23+
# To enable ssh & remote debugging on app service change the base image to the one below
24+
# FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0-appservice
25+
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0
26+
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
27+
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
28+
29+
COPY --from=function ["/home/site/wwwroot", "/home/site/wwwroot"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace NHS.CohortManager.ExceptionService;
2+
3+
using System.Net;
4+
using System.Threading.Tasks;
5+
using Microsoft.Azure.Functions.Worker;
6+
using Microsoft.Azure.Functions.Worker.Http;
7+
using Microsoft.Extensions.Diagnostics.HealthChecks;
8+
9+
public class HealthCheckFunction
10+
{
11+
private readonly HealthCheckService _healthCheckService;
12+
13+
public HealthCheckFunction(HealthCheckService healthCheckService)
14+
{
15+
_healthCheckService = healthCheckService;
16+
}
17+
18+
[Function("health")]
19+
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req)
20+
{
21+
var healthReport = await _healthCheckService.CheckHealthAsync();
22+
23+
var response = req.CreateResponse(healthReport.Status == HealthStatus.Healthy ? HttpStatusCode.OK : HttpStatusCode.ServiceUnavailable);
24+
await response.WriteAsJsonAsync(new
25+
{
26+
status = healthReport.Status.ToString(),
27+
details = healthReport.Entries
28+
});
29+
30+
return response;
31+
}
32+
}

0 commit comments

Comments
 (0)