-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timer trigger for status and notification sending (#53)
* Added Update Status timer trigger Also started on notifications * Added notification sending * Update to ensure we only send when completed or failed * Update IntegrationEventProvider.cs * Fixed spelling error Also increased expire time for notification Moved dispatch of notifications events to status trigger * Added tests for notifications for repo * Update OrchestrationSettlementReportsAppFixture.cs * Update SettlementReportRequestHandlerIntegrationTests.cs * Added new function app project for our timer trigger * Updates after review * Update Program.cs * Added new project to output * Update action.yml * Update action.yml * Update Program.cs
- Loading branch information
1 parent
f6f370b
commit 7448e36
Showing
21 changed files
with
494 additions
and
9 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
...ort/DatabaseMigration/Scripts/202410261405_Add_IsNotificationSent_to_SettlementReport.sql
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,3 @@ | ||
ALTER TABLE [settlementreports].[SettlementReport] | ||
ADD [IsNotificationSent] [bit] NOT NULL DEFAULT(1); --For all existing records, we will assume that notification has been sent. | ||
GO |
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
46 changes: 46 additions & 0 deletions
46
...t-report/SettlementReports.Function/Functions/SettlementReportUpdateStatusTimerTrigger.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,46 @@ | ||
// Copyright 2020 Energinet DataHub A/S | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License2"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Energinet.DataHub.Core.Messaging.Communication.Publisher; | ||
using Energinet.DataHub.SettlementReport.Application.Handlers; | ||
using Microsoft.Azure.Functions.Worker; | ||
|
||
namespace SettlementReports.Function.Functions; | ||
|
||
internal sealed class SettlementReportUpdateStatusTimerTrigger | ||
{ | ||
private readonly IListSettlementReportJobsHandler _listSettlementReportJobsHandler; | ||
private readonly IPublisher _publisher; | ||
|
||
public SettlementReportUpdateStatusTimerTrigger( | ||
IListSettlementReportJobsHandler listSettlementReportJobsHandler, | ||
IPublisher publisher) | ||
{ | ||
_listSettlementReportJobsHandler = listSettlementReportJobsHandler; | ||
_publisher = publisher; | ||
} | ||
|
||
[Function(nameof(UpdateStatusForSettlementReports))] | ||
public async Task UpdateStatusForSettlementReports( | ||
[TimerTrigger("0 */5 * * * *")] TimerInfo timer, | ||
FunctionContext executionContext) | ||
{ | ||
ArgumentNullException.ThrowIfNull(executionContext); | ||
|
||
// We are not interested in the result of the handler, as the handler will update the status of the settlement reports | ||
// It will also handle sending Notifications to the expected recipients | ||
await _listSettlementReportJobsHandler.HandleAsync().ConfigureAwait(false); | ||
await _publisher.PublishAsync(executionContext.CancellationToken).ConfigureAwait(false); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
source/settlement-report/SettlementReports.Function/Program.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,47 @@ | ||
// Copyright 2020 Energinet DataHub A/S | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License2"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Energinet.DataHub.Core.App.Common.Extensions.DependencyInjection; | ||
using Energinet.DataHub.Core.App.FunctionApp.Extensions.Builder; | ||
using Energinet.DataHub.Core.App.FunctionApp.Extensions.DependencyInjection; | ||
using Energinet.DataHub.RevisionLog.Integration.Extensions.DependencyInjection; | ||
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Security; | ||
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Telemetry; | ||
using Energinet.DataHub.SettlementReport.Infrastructure.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
var host = new HostBuilder() | ||
.ConfigureFunctionsWebApplication() | ||
.ConfigureServices((context, services) => | ||
{ | ||
// Common | ||
services.AddApplicationInsightsForIsolatedWorker(SubsystemInformation.SubsystemName); | ||
services.AddHealthChecksForIsolatedWorker(); | ||
|
||
// Shared by modules | ||
services.AddNodaTimeForApplication(); | ||
|
||
// revision log | ||
services.AddRevisionLogIntegrationModule(context.Configuration); | ||
|
||
// Modules | ||
services.AddSettlementReportsV2Module(context.Configuration); | ||
}) | ||
.ConfigureLogging((hostingContext, logging) => | ||
{ | ||
logging.AddLoggingConfigurationForIsolatedWorker(hostingContext); | ||
}) | ||
.Build(); | ||
|
||
host.Run(); |
9 changes: 9 additions & 0 deletions
9
source/settlement-report/SettlementReports.Function/Properties/launchSettings.json
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 @@ | ||
{ | ||
"profiles": { | ||
"SettlementReports.Function": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--port 7232", | ||
"launchBrowser": false | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
source/settlement-report/SettlementReports.Function/SettlementReports.Function.csproj
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,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<AzureFunctionsVersion>V4</AzureFunctionsVersion> | ||
<OutputType>Exe</OutputType> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Energinet.DataHub.RevisionLog.Integration" Version="1.1.3" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" /> | ||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" /> | ||
<PackageReference Include="Energinet.DataHub.Core.App.FunctionApp" Version="13.3.0" /> | ||
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.4.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.18.1" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Common.Infrastructure\Common.Infrastructure.csproj" /> | ||
<ProjectReference Include="..\SettlementReports.Infrastructure\SettlementReports.Infrastructure.csproj" /> | ||
<ProjectReference Include="..\SettlementReports.Interfaces\SettlementReports.Interfaces.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/> | ||
</ItemGroup> | ||
</Project> |
12 changes: 12 additions & 0 deletions
12
source/settlement-report/SettlementReports.Function/host.json
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,12 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true, | ||
"excludedTypes": "Request" | ||
}, | ||
"enableLiveMetricsFilters": true | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...nt-report/SettlementReports.Infrastructure/Contracts/UserNotificationTriggeredMetadata.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,21 @@ | ||
// Copyright 2020 Energinet DataHub A/S | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License2"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace Energinet.DataHub.SettlementReport.Infrastructure.Contracts; | ||
|
||
public partial class UserNotificationTriggered | ||
{ | ||
public const string EventName = "UserNotificationTriggered"; | ||
public const int CurrentMinorVersion = 1; | ||
} |
65 changes: 65 additions & 0 deletions
65
...ement-report/SettlementReports.Infrastructure/Contracts/user_notification_triggered.proto
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,65 @@ | ||
/* Copyright 2020 Energinet DataHub A/S | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License2"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
syntax = "proto3"; | ||
import "google/protobuf/timestamp.proto"; | ||
|
||
option csharp_namespace = "Energinet.DataHub.SettlementReport.Infrastructure.Contracts"; | ||
|
||
/* | ||
* UserNotificationTriggered Integration Event. | ||
* | ||
* Occurs when some action triggers the notification of a set of users. | ||
*/ | ||
message UserNotificationTriggered { | ||
|
||
/* | ||
* An identifier specifying the reason for the notification. | ||
*/ | ||
string reason_identifier = 1; | ||
|
||
/* | ||
* The unique identifier of the actor whose users will receive the notification. | ||
*/ | ||
string target_actor_id = 2; | ||
|
||
oneof target { | ||
|
||
/* | ||
* The unique identifier of the user that should receive the notification. | ||
*/ | ||
string target_user_id = 3; | ||
|
||
/* | ||
* The unique identifier of the group of users having the specified permission that should receive the notification. | ||
*/ | ||
string target_permissions = 4; | ||
} | ||
|
||
/* | ||
* A reason-specific id of an entity that the notification targets. | ||
*/ | ||
string related_id = 5; | ||
|
||
/* | ||
* A timestamp for when the notification was generated. | ||
*/ | ||
google.protobuf.Timestamp occurred_at = 6; | ||
|
||
/* | ||
* A timestamp for when the notification expires by itself. | ||
*/ | ||
google.protobuf.Timestamp expires_at = 7; | ||
} |
Oops, something went wrong.