-
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.
Feature/duplicate confirm handling (#331)
* Duplicate handling on confirm Download * Add start script to run dev * Format * Resolve conversation + cleanup * rethrow error message after deletion --------- Co-authored-by: Hammerbeck <andreas.hammerbeck@digdir.no>
- Loading branch information
Showing
19 changed files
with
126 additions
and
93 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
13 changes: 7 additions & 6 deletions
13
....Broker.API/Helpers/WebhookEventHelper.cs → ...ker.API/Helpers/IdempotencyEventHelper.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
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
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/Altinn.Broker.Core/Repositories/IIdempotencyEventRepository.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 @@ | ||
namespace Altinn.Broker.Core.Repositories | ||
{ | ||
public interface IIdempotencyEventRepository | ||
{ | ||
Task AddIdempotencyEventAsync(string id, CancellationToken cancellationToken); | ||
Task DeleteIdempotencyEventAsync(string id, CancellationToken cancellationToken); | ||
Task DeleteOldIdempotencyEvents(); | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
src/Altinn.Broker.Core/Repositories/IWebhookEventRepository.cs
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
src/Altinn.Broker.Integrations/Hangfire/IdempotencyService.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,28 @@ | ||
using System.Threading.Tasks; | ||
|
||
using Altinn.Broker.Core.Repositories; | ||
|
||
using Hangfire; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
public class IdempotencyService | ||
{ | ||
private readonly IIdempotencyEventRepository _idempotencyEventRepository; | ||
private readonly ILogger<IdempotencyService> _logger; | ||
|
||
public IdempotencyService( | ||
IIdempotencyEventRepository idempotencyEventRepository, | ||
ILogger<IdempotencyService> logger) | ||
{ | ||
_idempotencyEventRepository = idempotencyEventRepository; | ||
_logger = logger; | ||
} | ||
|
||
[AutomaticRetry(Attempts = 0)] | ||
public async Task DeleteOldIdempotencyEvents() | ||
{ | ||
_logger.LogInformation("Deleting old idempotency events"); | ||
await _idempotencyEventRepository.DeleteOldIdempotencyEvents(); | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
src/Altinn.Broker.Persistence/Migrations/V0003__idempotency_event.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,4 @@ | ||
CREATE TABLE broker.idempotency_event ( | ||
idempotency_event_id_pk character varying(80) PRIMARY KEY, | ||
created timestamp without time zone NOT NULL | ||
); |
4 changes: 0 additions & 4 deletions
4
src/Altinn.Broker.Persistence/Migrations/V0003__webhook_event.sql
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/Altinn.Broker.Persistence/Migrations/V0004__add_resourcename.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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ALTER TABLE broker.resource_owner | ||
ADD resource_group_name uuid NOT NULL; | ||
ADD resource_group_name uuid NOT NULL; |
46 changes: 46 additions & 0 deletions
46
src/Altinn.Broker.Persistence/Repositories/IdempotencyEventRepository.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 @@ | ||
using Altinn.Broker.Core.Repositories; | ||
|
||
using Npgsql; | ||
|
||
namespace Altinn.Broker.Persistence.Repositories; | ||
|
||
public class IdempotencyEventRepository : IIdempotencyEventRepository | ||
{ | ||
private DatabaseConnectionProvider _connectionProvider; | ||
|
||
public IdempotencyEventRepository(DatabaseConnectionProvider connectionProvider) | ||
{ | ||
_connectionProvider = connectionProvider; | ||
} | ||
|
||
|
||
public async Task AddIdempotencyEventAsync(string IdempotencyEventId, CancellationToken cancellationToken) | ||
{ | ||
NpgsqlCommand command = await _connectionProvider.CreateCommand( | ||
"INSERT INTO broker.idempotency_event (idempotency_event_id_pk, created)" + | ||
"VALUES (@idempotency_event_id_pk, @created) "); | ||
command.Parameters.AddWithValue("@idempotency_event_id_pk", IdempotencyEventId); | ||
command.Parameters.AddWithValue("@created", DateTime.UtcNow); | ||
|
||
await command.ExecuteNonQueryAsync(cancellationToken); | ||
} | ||
public async Task DeleteIdempotencyEventAsync(string IdempotencyEventId, CancellationToken cancellationToken) | ||
{ | ||
NpgsqlCommand command = await _connectionProvider.CreateCommand( | ||
"DELETE FROM broker.idempotency_event " + | ||
"WHERE idempotency_event_id_pk = @idempotency_event_id_pk"); | ||
command.Parameters.AddWithValue("@idempotency_event_id_pk", IdempotencyEventId); | ||
|
||
await command.ExecuteNonQueryAsync(cancellationToken); | ||
} | ||
public async Task DeleteOldIdempotencyEvents() | ||
{ | ||
NpgsqlCommand command = await _connectionProvider.CreateCommand( | ||
"DELETE FROM broker.idempotency_event " + | ||
"WHERE created < @created"); | ||
|
||
command.Parameters.AddWithValue("@created", DateTime.UtcNow.AddDays(-1)); | ||
|
||
await command.ExecuteNonQueryAsync(); | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
src/Altinn.Broker.Persistence/Repositories/WebhookEventRepository.cs
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
docker compose up -d | ||
dotnet watch --project ./src/Altinn.Broker.API/Altinn.Broker.API.csproj |