feat(siteeventlog): emit script started/completed Info events (M1.8)
ScriptExecutionActor previously emitted only an Error 'script' event on failure. It now also fire-and-forgets an Info 'script' event when execution starts (right before RunAsync) and when it completes successfully — giving the operational log the full started/completed/failed lifecycle. Uses the already-resolved siteEventLogger; fire-and-forget so the event log can never block or fault the script's own run. Extends the SingleServiceProvider test helper to also serve IServiceScopeFactory (returning a self-scope) so ScriptExecutionActor's serviceProvider.CreateScope() reaches the logging hot path in tests instead of throwing into the catch.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteEventLogging;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.TestSupport;
|
||||
@@ -51,12 +52,32 @@ public sealed class FakeSiteEventLogger : ISiteEventLogger
|
||||
/// <see cref="ISiteEventLogger"/> — enough for the actors' optional
|
||||
/// <c>_serviceProvider?.GetService<ISiteEventLogger>()</c> resolution
|
||||
/// without pulling a full DI container into the actor tests.
|
||||
/// <para>
|
||||
/// Also serves <see cref="IServiceScopeFactory"/> (returning a scope that just
|
||||
/// re-exposes this provider) so callers that do
|
||||
/// <c>serviceProvider.CreateScope()</c> — e.g. <c>ScriptExecutionActor</c> —
|
||||
/// don't throw before they reach the logging hot path.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class SingleServiceProvider(ISiteEventLogger logger) : IServiceProvider
|
||||
public sealed class SingleServiceProvider(ISiteEventLogger logger)
|
||||
: IServiceProvider, IServiceScopeFactory, IServiceScope
|
||||
{
|
||||
private readonly ISiteEventLogger _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? GetService(Type serviceType) =>
|
||||
serviceType == typeof(ISiteEventLogger) ? _logger : null;
|
||||
public object? GetService(Type serviceType)
|
||||
{
|
||||
if (serviceType == typeof(ISiteEventLogger)) return _logger;
|
||||
if (serviceType == typeof(IServiceScopeFactory)) return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IServiceScope CreateScope() => this;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IServiceProvider ServiceProvider => this;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose() { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user