Pārlūkot izejas kodu

refactoring

master
Savorboard pirms 7 gadiem
vecāks
revīzija
6cdfc50ce4
2 mainītis faili ar 23 papildinājumiem un 23 dzēšanām
  1. +18
    -18
      src/DotNetCore.CAP/IBootstrapper.Default.cs
  2. +5
    -5
      src/DotNetCore.CAP/LoggerExtensions.cs

+ 18
- 18
src/DotNetCore.CAP/IBootstrapper.Default.cs Parādīt failu

@@ -19,6 +19,10 @@ namespace DotNetCore.CAP
private readonly ILogger<DefaultBootstrapper> _logger;
private Task _bootstrappingTask;

private IStorage Storage { get; }

private IEnumerable<IProcessingServer> Processors { get; }

public DefaultBootstrapper(
ILogger<DefaultBootstrapper> logger,
IStorage storage,
@@ -45,10 +49,6 @@ namespace DotNetCore.CAP
});
}

protected IStorage Storage { get; }

protected IEnumerable<IProcessingServer> Processors { get; }

public Task BootstrapAsync()
{
return _bootstrappingTask = BootstrapTaskAsync();
@@ -60,10 +60,22 @@ namespace DotNetCore.CAP

if (_cts.IsCancellationRequested) return;

await BootstrapCoreAsync();
_appLifetime.ApplicationStopping.Register(() =>
{
foreach (var item in Processors)
item.Dispose();
});

if (_cts.IsCancellationRequested) return;

await BootstrapCoreAsync();

_ctsRegistration.Dispose();
_cts.Dispose();
}

protected virtual Task BootstrapCoreAsync()
{
foreach (var item in Processors)
try
{
@@ -71,20 +83,8 @@ namespace DotNetCore.CAP
}
catch (Exception ex)
{
_logger.ServerStartedError(ex);
_logger.ProcessorsStartedError(ex);
}

_ctsRegistration.Dispose();
_cts.Dispose();
}

public virtual Task BootstrapCoreAsync()
{
_appLifetime.ApplicationStopping.Register(() =>
{
foreach (var item in Processors)
item.Dispose();
});
return Task.CompletedTask;
}
}

+ 5
- 5
src/DotNetCore.CAP/LoggerExtensions.cs Parādīt failu

@@ -6,7 +6,7 @@ namespace DotNetCore.CAP
internal static class LoggerExtensions
{
private static readonly Action<ILogger, int, int, Exception> _serverStarting;
private static readonly Action<ILogger, Exception> _serverStartingError;
private static readonly Action<ILogger, Exception> _processorsStartingError;
private static readonly Action<ILogger, Exception> _serverShuttingDown;
private static readonly Action<ILogger, string, Exception> _expectedOperationCanceledException;

@@ -31,10 +31,10 @@ namespace DotNetCore.CAP
1,
"Starting the processing server. Detected {MachineProcessorCount} machine processor(s). Initiating {ProcessorCount} job processor(s).");

_serverStartingError = LoggerMessage.Define(
_processorsStartingError = LoggerMessage.Define(
LogLevel.Error,
5,
"Starting the processing server throw an exception.");
"Starting the processors throw an exception.");

_serverShuttingDown = LoggerMessage.Define(
LogLevel.Debug,
@@ -149,9 +149,9 @@ namespace DotNetCore.CAP
_serverStarting(logger, machineProcessorCount, processorCount, null);
}

public static void ServerStartedError(this ILogger logger, Exception ex)
public static void ProcessorsStartedError(this ILogger logger, Exception ex)
{
_serverStartingError(logger, ex);
_processorsStartingError(logger, ex);
}

public static void ServerShuttingDown(this ILogger logger)


Notiek ielāde…
Atcelt
Saglabāt