3
0

Add resource skipping for store encoders

This commit is contained in:
Tomaž Jerman
2023-02-25 12:54:58 +01:00
parent f661206a79
commit 0bfc2a7f87
7 changed files with 245 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/cortezaproject/corteza/server/automation/types"
"github.com/cortezaproject/corteza/server/pkg/envoyx"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/store"
)
@@ -119,6 +120,12 @@ func (e StoreEncoder) prepareWorkflow(ctx context.Context, p envoyx.EncodeParams
existing, hasExisting := existing[i]
// Run expressions on the nodes
err = e.runEvals(ctx, hasExisting, n)
if err != nil {
return
}
if hasExisting {
// On existing, we don't need to re-do identifiers and references; simply
// changing up the internal resource is enough.
@@ -299,6 +306,12 @@ func (e StoreEncoder) prepareTrigger(ctx context.Context, p envoyx.EncodeParams,
existing, hasExisting := existing[i]
// Run expressions on the nodes
err = e.runEvals(ctx, hasExisting, n)
if err != nil {
return
}
if hasExisting {
// On existing, we don't need to re-do identifiers and references; simply
// changing up the internal resource is enough.
@@ -465,3 +478,21 @@ func (e *StoreEncoder) grabStorer(p envoyx.EncodeParams) (s store.Storer, err er
return
}
func (e *StoreEncoder) runEvals(ctx context.Context, existing bool, n *envoyx.Node) (err error) {
// Skip if
if n.Config.SkipIfEval == nil {
return
}
aux, err := expr.EmptyVars().Cast(map[string]any{
"missing": !existing,
})
if err != nil {
return
}
n.Evaluated.Skip, err = n.Config.SkipIfEval.Test(ctx, aux.(*expr.Vars))
return
}