feat: wire Inbound API Route.To().Call() to site instance scripts and add Roslyn compilation
Completes the Inbound API → site script call chain by adding RouteToCallRequest handlers in SiteCommunicationActor and DeploymentManagerActor. Also replaces the placeholder dispatch table in InboundScriptExecutor with Roslyn compilation of API method scripts at startup, enabling user-defined inbound API methods to call instance scripts across the cluster.
This commit is contained in:
@@ -3,7 +3,9 @@ using Microsoft.Extensions.Logging;
|
||||
using ScadaLink.Commons.Messages.Artifacts;
|
||||
using ScadaLink.Commons.Messages.DebugView;
|
||||
using ScadaLink.Commons.Messages.Deployment;
|
||||
using ScadaLink.Commons.Messages.InboundApi;
|
||||
using ScadaLink.Commons.Messages.Lifecycle;
|
||||
using ScadaLink.Commons.Messages.ScriptExecution;
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
using ScadaLink.HealthMonitoring;
|
||||
using ScadaLink.SiteRuntime.Messages;
|
||||
@@ -77,6 +79,9 @@ public class DeploymentManagerActor : ReceiveActor, IWithTimers
|
||||
Receive<UnsubscribeDebugViewRequest>(RouteDebugViewUnsubscribe);
|
||||
Receive<DebugSnapshotRequest>(RouteDebugSnapshot);
|
||||
|
||||
// Inbound API Route.To().Call() — route to Instance Actors
|
||||
Receive<RouteToCallRequest>(RouteInboundApiCall);
|
||||
|
||||
// Internal startup messages
|
||||
Receive<StartupConfigsLoaded>(HandleStartupConfigsLoaded);
|
||||
Receive<StartNextBatch>(HandleStartNextBatch);
|
||||
@@ -486,6 +491,41 @@ public class DeploymentManagerActor : ReceiveActor, IWithTimers
|
||||
}
|
||||
}
|
||||
|
||||
// ── Inbound API routing ──
|
||||
|
||||
private void RouteInboundApiCall(RouteToCallRequest request)
|
||||
{
|
||||
if (_instanceActors.TryGetValue(request.InstanceUniqueName, out var instanceActor))
|
||||
{
|
||||
// Convert to ScriptCallRequest and Ask the Instance Actor
|
||||
var scriptCall = new ScriptCallRequest(
|
||||
request.ScriptName, request.Parameters, 0, request.CorrelationId);
|
||||
var sender = Sender;
|
||||
instanceActor.Ask<ScriptCallResult>(scriptCall, TimeSpan.FromSeconds(30))
|
||||
.ContinueWith(t =>
|
||||
{
|
||||
if (t.IsCompletedSuccessfully)
|
||||
{
|
||||
var result = t.Result;
|
||||
return new RouteToCallResponse(
|
||||
request.CorrelationId, result.Success, result.ReturnValue,
|
||||
result.ErrorMessage, DateTimeOffset.UtcNow);
|
||||
}
|
||||
return new RouteToCallResponse(
|
||||
request.CorrelationId, false, null,
|
||||
t.Exception?.GetBaseException().Message ?? "Script call timed out",
|
||||
DateTimeOffset.UtcNow);
|
||||
}).PipeTo(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
Sender.Tell(new RouteToCallResponse(
|
||||
request.CorrelationId, false, null,
|
||||
$"Instance '{request.InstanceUniqueName}' not found on this site.",
|
||||
DateTimeOffset.UtcNow));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WP-33: Handles system-wide artifact deployment (shared scripts, external systems, etc.).
|
||||
/// Persists artifacts to SiteStorageService and recompiles shared scripts.
|
||||
|
||||
Reference in New Issue
Block a user