Skip to content

Commit

Permalink
Fix bug with listen error results
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed May 23, 2019
1 parent 648383a commit 9581a02
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
18 changes: 14 additions & 4 deletions api/execution_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/execution_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
6 changes: 5 additions & 1 deletion interface/grpc/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion interface/grpc/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion interface/grpc/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 9581a02

Please sign in to comment.