From ab68ace12b360eb981c5f8be182f66ab857931a1 Mon Sep 17 00:00:00 2001 From: Chris Ainsworth-Patrick Date: Thu, 11 Jan 2024 15:59:45 -0500 Subject: [PATCH] async query is not no data cherry pick from atomist-skills/goal-evaluation-skill@d1dda2efa4743a3d06ed67eab4a6412d517a3e5e --- policy/goals/types.go | 7 ++++++- policy/policy_handler/handler.go | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/policy/goals/types.go b/policy/goals/types.go index 92dbfe8..a42f6a1 100644 --- a/policy/goals/types.go +++ b/policy/goals/types.go @@ -73,6 +73,11 @@ type ( } GoalEvaluator interface { - EvaluateGoal(ctx context.Context, req skill.RequestContext, commonData CommonSubscriptionQueryResult, subscriptionResults [][]edn.RawMessage) ([]GoalEvaluationQueryResult, error) + EvaluateGoal(ctx context.Context, req skill.RequestContext, commonData CommonSubscriptionQueryResult, subscriptionResults [][]edn.RawMessage) (EvaluationResult, error) + } + + EvaluationResult struct { + EvaluationCompleted bool + Result []GoalEvaluationQueryResult } ) diff --git a/policy/policy_handler/handler.go b/policy/policy_handler/handler.go index 37beecc..0bb36e3 100644 --- a/policy/policy_handler/handler.go +++ b/policy/policy_handler/handler.go @@ -146,12 +146,19 @@ func (h EventHandler) evaluate(ctx context.Context, req skill.RequestContext, da req.Log.Infof("Evaluating goal %s for digest %s ", goalName, digest) evaluationTs := time.Now().UTC() - goalResults, err := evaluator.EvaluateGoal(ctx, req, commonResults, subscriptionResult) + evaluationResult, err := evaluator.EvaluateGoal(ctx, req, commonResults, subscriptionResult) if err != nil { req.Log.Errorf("Failed to evaluate goal %s for digest %s: %s", goal.Definition, digest, err.Error()) return skill.NewFailedStatus("Failed to evaluate goal") } + if !evaluationResult.EvaluationCompleted { + req.Log.Info("evaluation incomplete") + return skill.NewCompletedStatus("Evaluation incomplete") + } + + goalResults := evaluationResult.Result + for _, f := range h.transactFilters { if !f(ctx, req) { // if not transacting, we return results as part of the skill result