diff --git a/docs/requirements/Component-Communication.md b/docs/requirements/Component-Communication.md index 6d959e5..2a6472a 100644 --- a/docs/requirements/Component-Communication.md +++ b/docs/requirements/Component-Communication.md @@ -38,6 +38,7 @@ Both central and site clusters. Each side has communication actors that handle m - **Pattern**: Broadcast with per-site acknowledgment (deploy to all sites), or targeted to a single site (per-site deployment). - When shared scripts, external system definitions, database connections, data connections, notification lists, or SMTP configuration are explicitly deployed, central sends them to the target site(s). - Each site acknowledges receipt and reports success/failure independently. +- **Shared script deployment triggers immediate recompilation on the site** — the site's `SharedScriptLibrary` replaces its in-memory compiled code, making updated shared scripts available to all running instances without redeployment. Other artifact types (external systems, database connections, etc.) are stored but do not require recompilation. ### 4. Integration Routing (External System → Central → Site → Central → External System) - **Pattern**: Request/Response (brokered). diff --git a/docs/requirements/Component-InboundAPI.md b/docs/requirements/Component-InboundAPI.md index a4f989d..fad57e0 100644 --- a/docs/requirements/Component-InboundAPI.md +++ b/docs/requirements/Component-InboundAPI.md @@ -99,6 +99,21 @@ Each API method definition includes: - This allows complex request/response structures (e.g., an object containing properties and a list of nested objects). - Template attributes retain the simpler four-type system. The extended types apply only to Inbound API method definitions and External System Gateway method definitions. +## Script Compilation & Hot-Reload + +API method scripts are compiled at central startup — all method definitions are loaded from the configuration database and compiled into in-memory delegates. + +### Update Workflow + +- Updating a method via the CLI (`api-method update --id --code '...'`) or Management API triggers immediate recompilation (`CompileAndRegister`). The updated script takes effect on the next API call — no node restart is required. +- Creating a new method after startup: if the method is created but not yet compiled, the first invocation triggers lazy (on-demand) compilation. + +### Direct SQL Warning + +> **Do not edit API method scripts via direct SQL.** The in-memory compiled script will not be updated until the next node restart. Always use the CLI, Management API, or Central UI to modify API method scripts. + +--- + ## API Call Logging - **Only failures are logged.** Script execution errors (500 responses) are logged centrally. diff --git a/docs/requirements/Component-SiteRuntime.md b/docs/requirements/Component-SiteRuntime.md index 110298d..a802a23 100644 --- a/docs/requirements/Component-SiteRuntime.md +++ b/docs/requirements/Component-SiteRuntime.md @@ -209,6 +209,32 @@ When the Instance Actor is stopped (due to disable, delete, or redeployment), Ak --- +## Script Lifecycle + +All script types can be updated without restarting the cluster, but the mechanism differs per type. + +### Instance Scripts and Alarm On-Trigger Scripts + +- Compiled at deployment time when the Deployment Manager receives a flattened configuration and creates the Instance Actor hierarchy. +- **To update**: modify the script in the template, then redeploy the instance (`instance deploy --id `). +- Redeployment stops the existing Instance Actor and all its children, creates a new Instance Actor, and recompiles all scripts and alarms from the updated configuration. +- There is no way to hot-reload a single instance script without redeploying the entire instance. + +### Shared Scripts + +- Compiled at the site when received from central via artifact deployment (`deploy artifacts`). +- The `SharedScriptLibrary` replaces its in-memory compiled code dictionary under a lock, making updated code immediately available to all Script Actors. +- **To update**: modify the shared script via the CLI or UI, then run `deploy artifacts` to push the change to sites. +- No instance redeployment is required — running instances pick up the new shared script code on the next `Scripts.CallShared()` invocation. + +### Inbound API Method Scripts + +- See Component-InboundAPI.md for the compilation and hot-reload lifecycle of API method scripts. + +> **Warning**: Editing scripts via direct SQL does not trigger recompilation. The in-memory compiled script will remain stale until the next node restart or redeployment. Always use the CLI, Management API, or Central UI to modify scripts. + +--- + ## Script Runtime API Available to all Script Execution Actors and Alarm Execution Actors: diff --git a/src/ScadaLink.CLI/README.md b/src/ScadaLink.CLI/README.md index 092f56a..1c42fe9 100644 --- a/src/ScadaLink.CLI/README.md +++ b/src/ScadaLink.CLI/README.md @@ -1260,6 +1260,8 @@ scadalink --url api-method update --id [--name ] [--code