refactor: properly rename connections-related tables; top-level namespaces
This commit is contained in:
@@ -3,39 +3,40 @@ using ConnectionsAPI.Database;
|
||||
using ConnectionsAPI.Utility;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ConnectionsAPI.Events
|
||||
namespace ConnectionsAPI.Events;
|
||||
|
||||
public class ConnectionsSyncEvent : IEvent { }
|
||||
|
||||
public class ConnectionsSyncHandler(ILogger<ConnectionsSyncHandler> logger,
|
||||
IServiceScopeFactory scopeFactory) : IEventHandler<ConnectionsSyncEvent>
|
||||
{
|
||||
public class PuzzleSyncEvent : IEvent { }
|
||||
private readonly ILogger<ConnectionsSyncHandler> _logger = logger;
|
||||
private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
|
||||
|
||||
public class PuzzleSyncHandler(ILogger<PuzzleSyncHandler> logger, IServiceScopeFactory scopeFactory) : IEventHandler<PuzzleSyncEvent>
|
||||
public async Task HandleAsync(ConnectionsSyncEvent eventModel, CancellationToken ct)
|
||||
{
|
||||
private readonly ILogger<PuzzleSyncHandler> _logger = logger;
|
||||
private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
|
||||
|
||||
public async Task HandleAsync(PuzzleSyncEvent eventModel, CancellationToken ct)
|
||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
_logger.LogInformation("Received Connections Sync Event");
|
||||
try
|
||||
{
|
||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
_logger.LogInformation("Received Puzzle Sync Event");
|
||||
try
|
||||
{
|
||||
// construct scope
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
// get dependencies
|
||||
ConnectionsContext db = scope.ServiceProvider.GetRequiredService<ConnectionsContext>();
|
||||
HttpClient http = scope.ServiceProvider.GetRequiredService<IHttpClientFactory>().CreateClient();
|
||||
ILogger<SyncUtility> syncLogger = scope.ServiceProvider.GetRequiredService<ILogger<SyncUtility>>();
|
||||
// do the work
|
||||
await new SyncUtility(db, syncLogger, http).SyncPuzzlesAsync(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while executing puzzle sync event");
|
||||
}
|
||||
finally
|
||||
{
|
||||
stopwatch.Stop();
|
||||
}
|
||||
_logger.LogInformation("Puzzle Sync Event finished in {ts}", stopwatch.Elapsed);
|
||||
// construct scope
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
// get dependencies
|
||||
ConnectionsContext db = scope.ServiceProvider.GetRequiredService<ConnectionsContext>();
|
||||
HttpClient http = scope.ServiceProvider.GetRequiredService<IHttpClientFactory>().CreateClient();
|
||||
ILogger<SyncUtility> syncLogger = scope.ServiceProvider.GetRequiredService<ILogger<SyncUtility>>();
|
||||
// do the work
|
||||
await new SyncUtility(db, syncLogger, http).SyncPuzzlesAsync(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while executing Connections sync event");
|
||||
}
|
||||
finally
|
||||
{
|
||||
stopwatch.Stop();
|
||||
}
|
||||
_logger.LogInformation("Connections Sync Event finished in {ts}", stopwatch.Elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user