Skip to content

Commit

Permalink
collapse evaluators into goals package
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Norton committed Dec 25, 2023
1 parent aa84401 commit df50569
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
23 changes: 0 additions & 23 deletions policy/evaluators/evaluators.go

This file was deleted.

8 changes: 3 additions & 5 deletions policy/evaluators/differ.go → policy/goals/differ.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package evaluators
package goals

import (
"fmt"

"github.com/atomist-skills/go-skill/policy/goals"

"github.com/atomist-skills/go-skill"
"github.com/mitchellh/hashstructure/v2"
)

// GoalResultsDiffer checks if the current query results differ from the previous ones.
// It returns the storage id for the current query results.
func GoalResultsDiffer(log skill.Logger, queryResults []goals.GoalEvaluationQueryResult, digest string, goal goals.Goal, previousStorageId string) (bool, string, error) {
func GoalResultsDiffer(log skill.Logger, queryResults []GoalEvaluationQueryResult, digest string, goal Goal, previousStorageId string) (bool, string, error) {
log.Infof("Generating storage id for goal %s, image %s", goal.Definition, digest)
hash, err := hashstructure.Hash(queryResults, hashstructure.FormatV2, nil)
if err != nil {
Expand Down Expand Up @@ -43,7 +41,7 @@ func isRelevantParam(str string) bool {
}

// Returns the config hash for the current skill config
func GoalConfigsDiffer(log skill.Logger, config skill.Configuration, digest string, goal goals.Goal, previousConfigHash string) (bool, string, error) {
func GoalConfigsDiffer(log skill.Logger, config skill.Configuration, digest string, goal Goal, previousConfigHash string) (bool, string, error) {
log.Debugf("Generating config hash for goal %s, image %s", goal.Definition, digest)

params := config.Parameters
Expand Down
6 changes: 6 additions & 0 deletions policy/goals/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package goals

import (
"context"
"github.com/atomist-skills/go-skill/policy/query"
"time"

"github.com/atomist-skills/go-skill"
Expand Down Expand Up @@ -48,3 +50,7 @@ type GoalEvaluationResultEntity struct {
ConfigHash string `edn:"goal.result/config-hash"`
CreatedAt time.Time `edn:"goal.result/created-at"`
}

type GoalEvaluator interface {
EvaluateGoal(ctx context.Context, req skill.RequestContext, commonData query.CommonSubscriptionQueryResult, subscriptionResults [][]edn.RawMessage) ([]GoalEvaluationQueryResult, error)
}
7 changes: 3 additions & 4 deletions policy/policy_handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/atomist-skills/go-skill"
"github.com/atomist-skills/go-skill/policy/data"
"github.com/atomist-skills/go-skill/policy/evaluators"
"github.com/atomist-skills/go-skill/policy/goals"
"github.com/atomist-skills/go-skill/policy/query"
"github.com/atomist-skills/go-skill/policy/storage"
Expand All @@ -16,7 +15,7 @@ import (
)

type (
EvaluatorSelector func(ctx context.Context, req skill.RequestContext, goal goals.Goal, dataSource data.DataSource) (evaluators.GoalEvaluator, error)
EvaluatorSelector func(ctx context.Context, req skill.RequestContext, goal goals.Goal, dataSource data.DataSource) (goals.GoalEvaluator, error)

Handler interface {
Start()
Expand Down Expand Up @@ -185,14 +184,14 @@ func transact(
return skill.NewFailedStatus(fmt.Sprintf("Failed to create evaluation storage: %s", err.Error()))
}

configDiffer, configHash, err := evaluators.GoalConfigsDiffer(req.Log, configuration, digest, goal, configHash)
configDiffer, configHash, err := goals.GoalConfigsDiffer(req.Log, configuration, digest, goal, configHash)
if err != nil {
req.Log.Errorf("Failed to check if config hash changed for digest: %s", digest, err)
req.Log.Warnf("Will continue with the evaluation nonetheless")
configDiffer = true
}

differ, storageId, err := evaluators.GoalResultsDiffer(req.Log, goalResults, digest, goal, storageId)
differ, storageId, err := goals.GoalResultsDiffer(req.Log, goalResults, digest, goal, storageId)
if err != nil {
req.Log.Errorf("Failed to check if goal results changed for digest: %s", digest, err)
req.Log.Warnf("Will continue with the evaluation nonetheless")
Expand Down

0 comments on commit df50569

Please sign in to comment.