Skip to content

Commit

Permalink
Remove output key from api filter
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed May 22, 2019
1 parent 5ec321f commit 98467cb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
17 changes: 3 additions & 14 deletions api/api.go
Expand Up @@ -164,20 +164,9 @@ func (a *API) ListenExecution(service string, f *ExecutionFilter) (*ExecutionLis
return nil, err
}

if f != nil {
if f.TaskKey == "" && f.OutputKey != "" {
return nil, fmt.Errorf("execution filter: output key given without task key")
}
if f.HasTaskKey() {
task, err := s.GetTask(f.TaskKey)
if err != nil {
return nil, err
}
if f.HasOutputKey() {
if _, err := task.GetOutput(f.OutputKey); err != nil {
return nil, err
}
}
if f != nil && f.HasTaskKey() {
if _, err := s.GetTask(f.TaskKey); err != nil {
return nil, err
}
}

Expand Down
15 changes: 3 additions & 12 deletions api/execution_listener.go
Expand Up @@ -8,10 +8,9 @@ import (

// ExecutionFilter store fileds for matching executions.
type ExecutionFilter struct {
Status execution.Status
TaskKey string
OutputKey string
Tags []string
Status execution.Status
TaskKey string
Tags []string
}

// Match matches execution.
Expand All @@ -22,9 +21,6 @@ func (f *ExecutionFilter) Match(e *execution.Execution) bool {
if f.TaskKey != "" && f.TaskKey != "*" && f.TaskKey != e.TaskKey {
return false
}
if f.OutputKey != "" && f.OutputKey != "*" && f.OutputKey != e.OutputKey {
return false
}
if f.Status != 0 && f.Status != e.Status {
return false
}
Expand All @@ -41,11 +37,6 @@ func (f *ExecutionFilter) HasTaskKey() bool {
return f != nil && f.TaskKey != "" && f.TaskKey != "*"
}

// HasOutputKey returns true if output key is set to specified value.
func (f *ExecutionFilter) HasOutputKey() bool {
return f != nil && f.OutputKey != "" && f.OutputKey != "*"
}

// ExecutionListener provides functionalities to listen MESG tasks.
type ExecutionListener struct {
// Channel receives matching executions for tasks.
Expand Down
15 changes: 0 additions & 15 deletions api/execution_listener_test.go
Expand Up @@ -49,21 +49,6 @@ func TestExecutionFilter(t *testing.T) {
&execution.Execution{TaskKey: "1"},
false,
},
{
&ExecutionFilter{OutputKey: "0"},
&execution.Execution{OutputKey: "0"},
true,
},
{
&ExecutionFilter{OutputKey: "*"},
&execution.Execution{OutputKey: "0"},
true,
},
{
&ExecutionFilter{OutputKey: "0"},
&execution.Execution{OutputKey: "1"},
false,
},
{
&ExecutionFilter{Tags: []string{"0"}},
&execution.Execution{Tags: []string{"0"}},
Expand Down
8 changes: 3 additions & 5 deletions interface/grpc/core/core.go
Expand Up @@ -142,10 +142,9 @@ 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,
TaskKey: request.TaskFilter,
OutputKey: request.OutputFilter,
Tags: request.TagFilters,
Status: execution.Completed,
TaskKey: request.TaskFilter,
Tags: request.TagFilters,
}
ln, err := s.api.ListenExecution(request.ServiceID, filter)
if err != nil {
Expand All @@ -172,7 +171,6 @@ func (s *Server) ListenResult(request *coreapi.ListenResultRequest, stream corea
if err := stream.Send(&coreapi.ResultData{
ExecutionID: execution.ID,
TaskKey: execution.TaskKey,
OutputKey: execution.OutputKey,
OutputData: string(outputs),
ExecutionTags: execution.Tags,
Error: execution.Error,
Expand Down

0 comments on commit 98467cb

Please sign in to comment.