@@ -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; | |||
} | |||
} |
@@ -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) | |||