fix: lazy-compile API method scripts and prefix composed alarm trigger attributes
- InboundScriptExecutor lazy-compiles scripts on first request, solving the multi-node problem where methods created via CLI/UI were only compiled on the ManagementActor's node, not the node handling the HTTP request. - ManagementActor hot-registers API method scripts on create/update/delete for the local node. - FlatteningService prefixes the "attribute" field in composed alarm trigger configs with the composition instance name so alarms evaluate against the correct path-qualified attribute (e.g. CoolingTank.Level not Level).
This commit is contained in:
@@ -1059,6 +1059,10 @@ public class ManagementActor : ReceiveActor
|
||||
};
|
||||
await repo.AddApiMethodAsync(method);
|
||||
await repo.SaveChangesAsync();
|
||||
|
||||
// Hot-register the compiled script so it's immediately available
|
||||
sp.GetService<InboundAPI.InboundScriptExecutor>()?.CompileAndRegister(method);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
@@ -1073,14 +1077,24 @@ public class ManagementActor : ReceiveActor
|
||||
method.ReturnDefinition = cmd.ReturnDefinition;
|
||||
await repo.UpdateApiMethodAsync(method);
|
||||
await repo.SaveChangesAsync();
|
||||
|
||||
// Re-compile and register the updated script
|
||||
sp.GetService<InboundAPI.InboundScriptExecutor>()?.CompileAndRegister(method);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
private static async Task<object?> HandleDeleteApiMethod(IServiceProvider sp, DeleteApiMethodCommand cmd)
|
||||
{
|
||||
var repo = sp.GetRequiredService<IInboundApiRepository>();
|
||||
var method = await repo.GetApiMethodByIdAsync(cmd.ApiMethodId);
|
||||
await repo.DeleteApiMethodAsync(cmd.ApiMethodId);
|
||||
await repo.SaveChangesAsync();
|
||||
|
||||
// Remove the compiled script handler
|
||||
if (method != null)
|
||||
sp.GetService<InboundAPI.InboundScriptExecutor>()?.RemoveHandler(method.Name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
<ProjectReference Include="../ScadaLink.Communication/ScadaLink.Communication.csproj" />
|
||||
<ProjectReference Include="../ScadaLink.Security/ScadaLink.Security.csproj" />
|
||||
<ProjectReference Include="../ScadaLink.HealthMonitoring/ScadaLink.HealthMonitoring.csproj" />
|
||||
<ProjectReference Include="..\ScadaLink.InboundAPI\ScadaLink.InboundAPI.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user