fix(triggers): seed the trigger-expression attribute snapshot at actor startup
This commit is contained in:
@@ -72,6 +72,7 @@ public class AlarmActor : ReceiveActor
|
|||||||
SiteRuntimeOptions options,
|
SiteRuntimeOptions options,
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
Script<object?>? compiledTriggerExpression = null,
|
Script<object?>? compiledTriggerExpression = null,
|
||||||
|
IReadOnlyDictionary<string, object?>? initialAttributes = null,
|
||||||
ISiteHealthCollector? healthCollector = null)
|
ISiteHealthCollector? healthCollector = null)
|
||||||
{
|
{
|
||||||
_alarmName = alarmName;
|
_alarmName = alarmName;
|
||||||
@@ -86,6 +87,15 @@ public class AlarmActor : ReceiveActor
|
|||||||
_onTriggerCompiledScript = onTriggerCompiledScript;
|
_onTriggerCompiledScript = onTriggerCompiledScript;
|
||||||
_compiledTriggerExpression = compiledTriggerExpression;
|
_compiledTriggerExpression = compiledTriggerExpression;
|
||||||
|
|
||||||
|
// Seed the trigger-expression attribute snapshot from the instance's
|
||||||
|
// initial attribute set so static attributes (which never re-emit an
|
||||||
|
// AttributeValueChanged after deploy) evaluate correctly at startup.
|
||||||
|
if (initialAttributes != null)
|
||||||
|
{
|
||||||
|
foreach (var kvp in initialAttributes)
|
||||||
|
_attributeSnapshot[kvp.Key] = kvp.Value;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse trigger type
|
// Parse trigger type
|
||||||
_triggerType = Enum.TryParse<AlarmTriggerType>(alarmConfig.TriggerType, true, out var tt)
|
_triggerType = Enum.TryParse<AlarmTriggerType>(alarmConfig.TriggerType, true, out var tt)
|
||||||
? tt : AlarmTriggerType.ValueMatch;
|
? tt : AlarmTriggerType.ValueMatch;
|
||||||
|
|||||||
@@ -529,6 +529,7 @@ public class InstanceActor : ReceiveActor
|
|||||||
_options,
|
_options,
|
||||||
_logger,
|
_logger,
|
||||||
triggerExpression,
|
triggerExpression,
|
||||||
|
_attributes,
|
||||||
_healthCollector,
|
_healthCollector,
|
||||||
_serviceProvider));
|
_serviceProvider));
|
||||||
|
|
||||||
@@ -578,6 +579,7 @@ public class InstanceActor : ReceiveActor
|
|||||||
_options,
|
_options,
|
||||||
_logger,
|
_logger,
|
||||||
triggerExpression,
|
triggerExpression,
|
||||||
|
_attributes,
|
||||||
_healthCollector));
|
_healthCollector));
|
||||||
|
|
||||||
var actorRef = Context.ActorOf(props, $"alarm-{alarm.CanonicalName}");
|
var actorRef = Context.ActorOf(props, $"alarm-{alarm.CanonicalName}");
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class ScriptActor : ReceiveActor, IWithTimers
|
|||||||
SiteRuntimeOptions options,
|
SiteRuntimeOptions options,
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
Script<object?>? compiledTriggerExpression = null,
|
Script<object?>? compiledTriggerExpression = null,
|
||||||
|
IReadOnlyDictionary<string, object?>? initialAttributes = null,
|
||||||
ISiteHealthCollector? healthCollector = null,
|
ISiteHealthCollector? healthCollector = null,
|
||||||
IServiceProvider? serviceProvider = null)
|
IServiceProvider? serviceProvider = null)
|
||||||
{
|
{
|
||||||
@@ -76,6 +77,15 @@ public class ScriptActor : ReceiveActor, IWithTimers
|
|||||||
_scope = scriptConfig.Scope;
|
_scope = scriptConfig.Scope;
|
||||||
_compiledTriggerExpression = compiledTriggerExpression;
|
_compiledTriggerExpression = compiledTriggerExpression;
|
||||||
|
|
||||||
|
// Seed the trigger-expression attribute snapshot from the instance's
|
||||||
|
// initial attribute set so static attributes (which never re-emit an
|
||||||
|
// AttributeValueChanged after deploy) evaluate correctly at startup.
|
||||||
|
if (initialAttributes != null)
|
||||||
|
{
|
||||||
|
foreach (var kvp in initialAttributes)
|
||||||
|
_attributeSnapshot[kvp.Key] = kvp.Value;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse trigger configuration
|
// Parse trigger configuration
|
||||||
_triggerConfig = ParseTriggerConfig(scriptConfig.TriggerType, scriptConfig.TriggerConfiguration);
|
_triggerConfig = ParseTriggerConfig(scriptConfig.TriggerType, scriptConfig.TriggerConfiguration);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user