diff --git a/src/DotNetCore.CAP/IBootstrapper.Default.cs b/src/DotNetCore.CAP/IBootstrapper.Default.cs index 8359211..64f298c 100644 --- a/src/DotNetCore.CAP/IBootstrapper.Default.cs +++ b/src/DotNetCore.CAP/IBootstrapper.Default.cs @@ -19,6 +19,10 @@ namespace DotNetCore.CAP private readonly ILogger _logger; private Task _bootstrappingTask; + private IStorage Storage { get; } + + private IEnumerable Processors { get; } + public DefaultBootstrapper( ILogger logger, IStorage storage, @@ -45,10 +49,6 @@ namespace DotNetCore.CAP }); } - protected IStorage Storage { get; } - - protected IEnumerable 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; } } diff --git a/src/DotNetCore.CAP/LoggerExtensions.cs b/src/DotNetCore.CAP/LoggerExtensions.cs index 49fe4a8..1352fda 100644 --- a/src/DotNetCore.CAP/LoggerExtensions.cs +++ b/src/DotNetCore.CAP/LoggerExtensions.cs @@ -6,7 +6,7 @@ namespace DotNetCore.CAP internal static class LoggerExtensions { private static readonly Action _serverStarting; - private static readonly Action _serverStartingError; + private static readonly Action _processorsStartingError; private static readonly Action _serverShuttingDown; private static readonly Action _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)