feat(adminui): IAdminOperationsClient backed by ClusterSingletonProxy
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
using Akka.Actor;
|
||||||
|
using Akka.Hosting;
|
||||||
|
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||||
|
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
|
||||||
|
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||||
|
using ZB.MOM.WW.OtOpcUa.ControlPlane;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="IAdminOperationsClient"/> backed by the cluster singleton registered in
|
||||||
|
/// <c>AddOtOpcUaControlPlane</c>. Resolves the singleton proxy from <see cref="ActorRegistry"/>
|
||||||
|
/// at construction time; each call <c>Ask</c>s the proxy with a 10s timeout.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AdminOperationsClient : IAdminOperationsClient
|
||||||
|
{
|
||||||
|
private static readonly TimeSpan AskTimeout = TimeSpan.FromSeconds(10);
|
||||||
|
|
||||||
|
private readonly IActorRef _proxy;
|
||||||
|
|
||||||
|
public AdminOperationsClient(ActorRegistry registry)
|
||||||
|
{
|
||||||
|
_proxy = registry.Get<AdminOperationsActorKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StartDeploymentResult> StartDeploymentAsync(string createdBy, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var msg = new StartDeployment(createdBy, CorrelationId.NewId());
|
||||||
|
using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||||
|
linked.CancelAfter(AskTimeout);
|
||||||
|
return await _proxy.Ask<StartDeploymentResult>(msg, AskTimeout, linked.Token);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients;
|
||||||
|
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddOtOpcUaAdminClients(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddScoped<IAdminOperationsClient, AdminOperationsClient>();
|
||||||
|
services.AddScoped<IFleetDiagnosticsClient, FleetDiagnosticsClient>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user