From 9581a0216fab48cea14dec11860f0db0aee907f1 Mon Sep 17 00:00:00 2001 From: krhubert Date: Wed, 22 May 2019 18:10:41 +0200 Subject: [PATCH] Fix bug with listen error results --- api/execution_listener.go | 18 ++++++++++++++---- api/execution_listener_test.go | 4 ++-- interface/grpc/core/core.go | 6 +++++- interface/grpc/service/service.go | 4 +++- interface/grpc/service/service_test.go | 5 ++++- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/api/execution_listener.go b/api/execution_listener.go index 467461c51..78b653387 100644 --- a/api/execution_listener.go +++ b/api/execution_listener.go @@ -8,9 +8,9 @@ import ( // ExecutionFilter store fileds for matching executions. type ExecutionFilter struct { - Status execution.Status - TaskKey string - Tags []string + Statuses []execution.Status + TaskKey string + Tags []string } // Match matches execution. @@ -21,9 +21,19 @@ func (f *ExecutionFilter) Match(e *execution.Execution) bool { if f.TaskKey != "" && f.TaskKey != "*" && f.TaskKey != e.TaskKey { return false } - if f.Status != 0 && f.Status != e.Status { + + match := len(f.Statuses) == 0 + for _, status := range f.Statuses { + if status == e.Status { + match = true + break + } + } + + if !match { return false } + for _, tag := range f.Tags { if !xstrings.SliceContains(e.Tags, tag) { return false diff --git a/api/execution_listener_test.go b/api/execution_listener_test.go index cb06323a4..d42fb4c46 100644 --- a/api/execution_listener_test.go +++ b/api/execution_listener_test.go @@ -25,12 +25,12 @@ func TestExecutionFilter(t *testing.T) { true, }, { - &ExecutionFilter{Status: execution.Created}, + &ExecutionFilter{Statuses: []execution.Status{execution.Created}}, &execution.Execution{Status: execution.Created}, true, }, { - &ExecutionFilter{Status: execution.Created}, + &ExecutionFilter{Statuses: []execution.Status{execution.Created}}, &execution.Execution{Status: execution.InProgress}, false, }, diff --git a/interface/grpc/core/core.go b/interface/grpc/core/core.go index 010935056..216743f0d 100644 --- a/interface/grpc/core/core.go +++ b/interface/grpc/core/core.go @@ -142,10 +142,14 @@ func (s *Server) ListenEvent(request *coreapi.ListenEventRequest, stream coreapi // ListenResult listens for results from a services. func (s *Server) ListenResult(request *coreapi.ListenResultRequest, stream coreapi.Core_ListenResultServer) error { filter := &api.ExecutionFilter{ - Status: execution.Completed, + Statuses: []execution.Status{ + execution.Completed, + execution.Failed, + }, TaskKey: request.TaskFilter, Tags: request.TagFilters, } + ln, err := s.api.ListenExecution(request.ServiceID, filter) if err != nil { return err diff --git a/interface/grpc/service/service.go b/interface/grpc/service/service.go index 69505be3c..d2affa130 100644 --- a/interface/grpc/service/service.go +++ b/interface/grpc/service/service.go @@ -11,7 +11,9 @@ import ( "github.com/mesg-foundation/core/protobuf/serviceapi" ) -var inProgressFilter = &api.ExecutionFilter{Status: execution.InProgress} +var inProgressFilter = &api.ExecutionFilter{ + Statuses: []execution.Status{execution.InProgress}, +} // Server binds all api functions. type Server struct { diff --git a/interface/grpc/service/service_test.go b/interface/grpc/service/service_test.go index 911607615..f402658d2 100644 --- a/interface/grpc/service/service_test.go +++ b/interface/grpc/service/service_test.go @@ -164,7 +164,10 @@ func TestSubmit(t *testing.T) { executionID, err := server.api.ExecuteTask(s.Hash, taskKey, taskData, nil) require.NoError(t, err) - ln, err := server.api.ListenExecution(s.Hash, &api.ExecutionFilter{Status: execution.Completed}) + ef := &api.ExecutionFilter{ + Statuses: []execution.Status{execution.Completed}, + } + ln, err := server.api.ListenExecution(s.Hash, ef) require.NoError(t, err) defer ln.Close()