Skip to content

Commit 8ba2cab

Browse files
committed
fix: compiler errors
1 parent 18b7128 commit 8ba2cab

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

Applications/IdentityDeletionJobs/src/Job.IdentityDeletion/Workers/ActualDeletionWorker.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,35 @@ namespace Backbone.Job.IdentityDeletion.Workers;
1313

1414
public class ActualDeletionWorker : IHostedService
1515
{
16-
public static ILogger<ActualDeletionWorker> Logger = null!;
16+
public static ILogger<ActualDeletionWorker>? Logger = null!;
1717

1818
private readonly IHostApplicationLifetime _host;
1919
private readonly IMediator _mediator;
2020
private readonly IPushNotificationSender _pushNotificationSender;
21+
private readonly ILogger<ActualDeletionWorker> _logger;
2122
private readonly List<IIdentityDeleter> _identityDeleters;
2223

2324
public ActualDeletionWorker(
2425
IHostApplicationLifetime host,
2526
IEnumerable<IIdentityDeleter> identityDeleters,
2627
IMediator mediator,
27-
IPushNotificationSender pushNotificationSender)
28+
IPushNotificationSender pushNotificationSender,
29+
ILogger<ActualDeletionWorker> logger)
2830
{
2931
_host = host;
3032
_identityDeleters = identityDeleters.ToList();
3133
_mediator = mediator;
3234
_pushNotificationSender = pushNotificationSender;
35+
_logger = Logger ?? logger;
3336
}
3437

3538
public async Task StartAsync(CancellationToken cancellationToken)
3639
{
37-
Logger.LogError("StartAsync start");
40+
_logger.LogError("StartAsync start");
3841
await StartProcessing(cancellationToken);
3942

4043
_host.StopApplication();
41-
Logger.LogError("StartAsync end");
44+
_logger.LogError("StartAsync end");
4245
}
4346

4447
public Task StopAsync(CancellationToken cancellationToken)
@@ -48,36 +51,36 @@ public Task StopAsync(CancellationToken cancellationToken)
4851

4952
public async Task StartProcessing(CancellationToken cancellationToken)
5053
{
51-
Logger.LogError("StartProcessing start");
54+
_logger.LogError("StartProcessing start");
5255
var response = await _mediator.Send(new TriggerRipeDeletionProcessesCommand(), cancellationToken);
5356

54-
Logger.LogError("There are {count} ripe deletion processes to be executed", response.Results.Count);
57+
_logger.LogError("There are {count} ripe deletion processes to be executed", response.Results.Count);
5558

5659
var addressesWithTriggeredDeletionProcesses = response.Results.Where(x => x.Value.IsSuccess).Select(x => x.Key);
5760
var erroringDeletionTriggers = response.Results.Where(x => x.Value.IsFailure);
5861

5962
await ExecuteDeletion(addressesWithTriggeredDeletionProcesses, cancellationToken);
6063
LogErroringDeletionTriggers(erroringDeletionTriggers);
61-
Logger.LogError("StartProcessing end");
64+
_logger.LogError("StartProcessing end");
6265
}
6366

6467
private async Task ExecuteDeletion(IEnumerable<IdentityAddress> addresses, CancellationToken cancellationToken)
6568
{
66-
Logger.LogError("ExecuteDeletion start");
69+
_logger.LogError("ExecuteDeletion start");
6770
foreach (var identityAddress in addresses)
6871
{
6972
await ExecuteDeletion(identityAddress, cancellationToken);
7073
}
7174

72-
Logger.LogError("ExecuteDeletion end");
75+
_logger.LogError("ExecuteDeletion end");
7376
}
7477

7578
private async Task ExecuteDeletion(IdentityAddress identityAddress, CancellationToken cancellationToken)
7679
{
77-
Logger.LogError("ExecuteDeletion start");
80+
_logger.LogError("ExecuteDeletion start");
7881
await NotifyIdentityAboutStartingDeletion(identityAddress, cancellationToken);
7982
await Delete(identityAddress);
80-
Logger.LogError("ExecuteDeletion end");
83+
_logger.LogError("ExecuteDeletion end");
8184
}
8285

8386
private async Task NotifyIdentityAboutStartingDeletion(IdentityAddress identityAddress, CancellationToken cancellationToken)
@@ -90,26 +93,26 @@ await _pushNotificationSender.SendNotification(
9093

9194
private async Task Delete(IdentityAddress identityAddress)
9295
{
93-
Logger.LogError("Delete start");
96+
_logger.LogError("Delete start");
9497
var identity = await _mediator.Send(new GetIdentityQuery(identityAddress.Value));
9598

9699
foreach (var identityDeleter in _identityDeleters)
97100
{
98-
Logger.LogError("Executing {name}", identityDeleter.GetType().FullName);
101+
_logger.LogError("Executing {name}", identityDeleter.GetType().FullName);
99102
await identityDeleter.Delete(identityAddress);
100103
}
101104

102105
var usernames = identity.Devices.Select(d => d.Username);
103106

104107
await _mediator.Send(new HandleCompletedDeletionProcessCommand(identityAddress.Value, usernames));
105-
Logger.LogError("Delete end");
108+
_logger.LogError("Delete end");
106109
}
107110

108111
private void LogErroringDeletionTriggers(IEnumerable<KeyValuePair<IdentityAddress, UnitResult<DomainError>>> erroringDeletionTriggers)
109112
{
110113
foreach (var erroringDeletion in erroringDeletionTriggers)
111114
{
112-
Logger.ErrorWhenTriggeringDeletionProcessForIdentity(erroringDeletion.Value.Error.Code, erroringDeletion.Value.Error.Message);
115+
_logger.ErrorWhenTriggeringDeletionProcessForIdentity(erroringDeletion.Value.Error.Code, erroringDeletion.Value.Error.Message);
113116
}
114117
}
115118
}

Applications/IdentityDeletionJobs/test/Job.IdentityDeletion.Tests/Tests/ActualDeletionWorkerTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using FakeItEasy;
1414
using MediatR;
1515
using Microsoft.Extensions.Hosting;
16+
using Microsoft.Extensions.Logging;
1617

1718
namespace Backbone.Job.IdentityDeletion.Tests.Tests;
1819

@@ -109,7 +110,8 @@ private static ActualDeletionWorker CreateWorker(IMediator mediator,
109110
var hostApplicationLifetime = A.Dummy<IHostApplicationLifetime>();
110111
identityDeleters ??= [A.Dummy<IIdentityDeleter>()];
111112
pushNotificationSender ??= A.Dummy<IPushNotificationSender>();
112-
return new ActualDeletionWorker(hostApplicationLifetime, identityDeleters, mediator, pushNotificationSender);
113+
var logger = A.Dummy<ILogger<ActualDeletionWorker>>();
114+
return new ActualDeletionWorker(hostApplicationLifetime, identityDeleters, mediator, pushNotificationSender, logger);
113115
}
114116

115117
private static Identity CreateIdentity()

BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static string CreateRandomString(int resultLength, char[]? chars = null)
1616

1717
public static IdentityAddress CreateRandomIdentityAddress()
1818
{
19-
return IdentityAddress.Create(CreateRandomBytes(), "prod.enmeshed.eu");
19+
return IdentityAddress.Create(CreateRandomBytes(), "localhost");
2020
}
2121

2222
public static DeviceId CreateRandomDeviceId()

Modules/Relationships/src/Relationships.Application/Relationships/Commands/DecomposeAndAnonymizeRelationshipsOfIdentity/Handler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Deco
1111

1212
public class Handler : IRequestHandler<DecomposeAndAnonymizeRelationshipsOfIdentityCommand>
1313
{
14-
public static ILogger<Handler> Logger = null!;
14+
public static ILogger<Handler>? Logger = null!;
1515

1616
private readonly IRelationshipsRepository _relationshipsRepository;
1717
private readonly ApplicationOptions _applicationOptions;
@@ -26,16 +26,16 @@ public async Task Handle(DecomposeAndAnonymizeRelationshipsOfIdentityCommand req
2626
{
2727
var relationships = (await _relationshipsRepository.FindRelationships(Relationship.HasParticipant(request.IdentityAddress), cancellationToken)).ToList();
2828

29-
Logger.LogError("Decomposing {n} relationships for identity {IdentityAddress}", relationships.Count, request.IdentityAddress);
29+
Logger?.LogError("Decomposing {n} relationships for identity {IdentityAddress}", relationships.Count, request.IdentityAddress);
3030

3131
foreach (var relationship in relationships)
3232
relationship.DecomposeDueToIdentityDeletion(request.IdentityAddress, _applicationOptions.DidDomainName);
3333

34-
Logger.LogError("Done decomposing relationships for identity {IdentityAddress}", request.IdentityAddress);
34+
Logger?.LogError("Done decomposing relationships for identity {IdentityAddress}", request.IdentityAddress);
3535

3636
var rel = relationships.FirstOrDefault();
3737

38-
Logger.LogError("Relationship: {rel}", JsonSerializer.Serialize(rel, new JsonSerializerOptions
38+
Logger?.LogError("Relationship: {rel}", JsonSerializer.Serialize(rel, new JsonSerializerOptions
3939
{
4040
ReferenceHandler = ReferenceHandler.IgnoreCycles,
4141
WriteIndented = true

0 commit comments

Comments
 (0)