56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Microsoft.Extensions.Logging;
|
|
using StellaOps.Plugin.Hosting;
|
|
|
|
namespace StellaOps.Notify.WebService.Plugins;
|
|
|
|
internal interface INotifyPluginRegistry
|
|
{
|
|
Task<int> WarmupAsync(CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
internal sealed class NotifyPluginRegistry : INotifyPluginRegistry
|
|
{
|
|
private readonly PluginHostOptions _hostOptions;
|
|
private readonly ILogger<NotifyPluginRegistry> _logger;
|
|
|
|
public NotifyPluginRegistry(
|
|
PluginHostOptions hostOptions,
|
|
ILogger<NotifyPluginRegistry> logger)
|
|
{
|
|
_hostOptions = hostOptions ?? throw new ArgumentNullException(nameof(hostOptions));
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
}
|
|
|
|
public Task<int> WarmupAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var result = PluginHost.LoadPlugins(_hostOptions, _logger);
|
|
|
|
if (result.Plugins.Count == 0)
|
|
{
|
|
_logger.LogWarning(
|
|
"No Notify plug-ins discovered under '{PluginDirectory}'.",
|
|
result.PluginDirectory);
|
|
}
|
|
else
|
|
{
|
|
_logger.LogInformation(
|
|
"Loaded {PluginCount} Notify plug-in(s) from '{PluginDirectory}'.",
|
|
result.Plugins.Count,
|
|
result.PluginDirectory);
|
|
}
|
|
|
|
if (result.MissingOrderedPlugins.Count > 0)
|
|
{
|
|
_logger.LogWarning(
|
|
"Configured plug-ins missing from disk: {Missing}.",
|
|
string.Join(", ", result.MissingOrderedPlugins));
|
|
}
|
|
|
|
return Task.FromResult(result.Plugins.Count);
|
|
}
|
|
}
|