@@ -81,22 +81,27 @@ func (svc *service) Run(triggerName string, vars map[string]interface{}) ([]Cond
8181 Templates : condition .Send ,
8282 Key : fmt .Sprintf ("[%d].%s" , i , hash (condition .When )),
8383 }
84-
84+ var whenResult bool
8585 if prog , ok := svc .compiledConditions [condition .When ]; ! ok {
8686 return nil , fmt .Errorf ("trigger configuration has changed after initialization" )
8787 } else if val , err := expr .Run (prog , vars ); err == nil {
8888 boolRes , ok := val .(bool )
8989 conditionResult .Triggered = ok && boolRes
90+ whenResult = conditionResult .Triggered
9091 } else {
9192 log .Errorf ("failed to execute when condition: %+v" , err )
9293 }
9394
94- if prog , ok := svc .compiledOncePer [condition .OncePer ]; ok {
95- if val , err := expr .Run (prog , vars ); err == nil {
96- conditionResult .OncePer = fmt .Sprintf ("%v" , val )
97- } else {
98- log .Errorf ("failed to execute oncePer condition: %+v" , err )
95+ if whenResult {
96+ if prog , ok := svc .compiledOncePer [condition .OncePer ]; ok {
97+ if val , err := expr .Run (prog , vars ); err == nil {
98+ conditionResult .OncePer = fmt .Sprintf ("%v" , val )
99+ } else {
100+ log .Errorf ("failed to execute oncePer condition: %+v" , err )
101+ }
99102 }
103+ } else {
104+ log .Debug ("The OncePer condition will not be evaluated since the when condition evaluates to false" )
100105 }
101106
102107 res = append (res , conditionResult )
0 commit comments