New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/tag executions #362
Changes from 16 commits
f60f431
6ea2908
44aed51
372df7a
d0e18e7
f7b4c87
0f79d9c
d70e67a
1e70f7c
15f8c10
12d3d3c
9cf0d6c
807647b
31445f2
bf23d88
5f98a3f
545f806
f29309c
f1fc1ff
c7ba093
e636606
635662b
8fa1c71
0937afe
48fe5ac
d5477e7
7117239
4d6b785
52009d5
4934408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,13 +79,15 @@ message EventData { | |
// { | ||
// "serviceID": "__SERVICE_ID__", | ||
// "taskFilter": "__TASK_KEY_TO_MATCH__", | ||
// "outputFilter": "__OUTPUT_KEY_TO_MATCH__" | ||
// "outputFilter": "__OUTPUT_KEY_TO_MATCH__", | ||
// "tagFilters": ["tagX"] | ||
// } | ||
// ``` | ||
message ListenResultRequest { | ||
string serviceID = 1; // The Service ID. Generated when using the [`DeployService` API](#deployservice). | ||
string taskFilter = 2; // __Optional.__ The task's key to filter. The task must match this key. The default is `*` which matches any task. | ||
string outputFilter = 3; // __Optional.__ The output's key from the task to filter. The task must return this output's key. The default is `*` which matches any output. | ||
string serviceID = 1; // The Service ID. Generated when using the [`DeployService` API](#deployservice). | ||
string taskFilter = 2; // __Optional.__ The task's key to filter. The task must match this key. The default is `*` which matches any task. | ||
string outputFilter = 3; // __Optional.__ The output's key from the task to filter. The task must return this output's key. The default is `*` which matches any output. | ||
repeated string tagFilters = 4; // __Optional.__ List of tags to filter. This is a "match all" list. All tags in parameters should be included in the execution to match. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add "The" at the beginning of the comment to look the same as other comments |
||
} | ||
|
||
// The data received from the stream of the `ListenResult` API. | ||
|
@@ -97,14 +99,16 @@ message ListenResultRequest { | |
// "executionID": "__EXECUTION_ID__", | ||
// "taskKey": "__TASK_KEY__", | ||
// "outputKey": "__OUTPUT_KEY__", | ||
// "outputData": "{\"foo\":\"bar\"}" | ||
// "outputData": "{\"foo\":\"bar\"}", | ||
// "tags": ["executionX", "test"] | ||
// } | ||
// ``` | ||
message ResultData { | ||
string executionID = 1; // The unique identifier of the execution. | ||
string taskKey = 2; // The key of the executed task. | ||
string outputKey = 3; // The output's key from the returned task. | ||
string outputData = 4; // The output's data from the returned task, encoded in JSON. | ||
string executionID = 1; // The unique identifier of the execution. | ||
string taskKey = 2; // The key of the executed task. | ||
string outputKey = 3; // The output's key from the returned task. | ||
string outputData = 4; // The output's data from the returned task, encoded in JSON. | ||
repeated string tags = 5; // The list of tags associated to the execution | ||
} | ||
|
||
// The request's data for the `ExecuteTask` API. | ||
|
@@ -114,13 +118,15 @@ message ResultData { | |
// { | ||
// "serviceID": "__SERVICE_ID__", | ||
// "taskKey": "__TASK_KEY__", | ||
// "inputData": "{\"foo\":\"bar\"}" | ||
// "inputData": "{\"foo\":\"bar\"}", | ||
// "tags": ["executionX", "test"] | ||
// } | ||
// ``` | ||
message ExecuteTaskRequest { | ||
string serviceID = 1; // The Service ID. Generated when using the [`DeployService` API](#deployservice). | ||
string taskKey = 2; // The task's key to execute. | ||
string inputData = 3; // The inputs of the task to execute, encoded in JSON. | ||
string serviceID = 1; // The Service ID. Generated when using the [`DeployService` API](#deployservice). | ||
string taskKey = 2; // The task's key to execute. | ||
string inputData = 3; // The inputs of the task to execute, encoded in JSON. | ||
repeated string tags = 4; // The list of tags to associate to the execution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My argument to name it That's what we did for all other parameters. Eg: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for the rest of the conversation I would love to have other feedbacks on that @ilgooz @krhubert ? Naming problem again :) For the naming of the tag parameter sent when executing a task or listening for the result of a task.
What do you think ? |
||
} | ||
|
||
// The reply's data of the `ExecuteTask` API. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,14 +126,14 @@ func TestExecuteFunc(t *testing.T) { | |
"test": {}, | ||
}, | ||
} | ||
id, err := execute(srv, "test", map[string]interface{}{}) | ||
id, err := execute(srv, "test", map[string]interface{}{}, []string{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can tags be nil? Everywhere there is an empty string slice, but I wonder if it's ok to use nil. I think it could be. (Maybe same for inputs?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes nil is fine too. Do you want me to replace with nil instead |
||
assert.Nil(t, err) | ||
assert.NotNil(t, id) | ||
} | ||
|
||
func TestExecuteFuncInvalidTaskName(t *testing.T) { | ||
srv := &service.Service{} | ||
_, err := execute(srv, "test", map[string]interface{}{}) | ||
_, err := execute(srv, "test", map[string]interface{}{}, []string{}) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,14 @@ func (s *Server) ListenResult(request *ListenResultRequest, stream Core_ListenRe | |
return ctx.Err() | ||
case data := <-subscription: | ||
execution := data.(*execution.Execution) | ||
if isSubscribedTask(request, execution) && isSubscribedOutput(request, execution) { | ||
if isSubscribedToTags(request, execution) && isSubscribedToTask(request, execution) && isSubscribedToOutput(request, execution) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to if isSubscribedToTags(request, execution) &&
isSubscribedToTask(request, execution) &&
isSubscribedToOutput(request, execution) {
} |
||
outputs, _ := json.Marshal(execution.OutputData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always check for err for even for json.Marshal (especially if there is an interface{} type as value) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch, it's present in other places too, I created a separated issue for that #374 |
||
if err := stream.Send(&ResultData{ | ||
ExecutionID: execution.ID, | ||
TaskKey: execution.Task, | ||
OutputKey: execution.Output, | ||
OutputData: string(outputs), | ||
Tags: execution.Tags, | ||
}); err != nil { | ||
return err | ||
} | ||
|
@@ -79,10 +80,22 @@ func validateOutputKey(service *service.Service, taskKey string, outputFilter st | |
return nil | ||
} | ||
|
||
func isSubscribedTask(request *ListenResultRequest, e *execution.Execution) bool { | ||
func isSubscribedToTask(request *ListenResultRequest, e *execution.Execution) bool { | ||
return array.IncludedIn([]string{"", "*", e.Task}, request.TaskFilter) | ||
} | ||
|
||
func isSubscribedOutput(request *ListenResultRequest, e *execution.Execution) bool { | ||
func isSubscribedToOutput(request *ListenResultRequest, e *execution.Execution) bool { | ||
return array.IncludedIn([]string{"", "*", e.Output}, request.OutputFilter) | ||
} | ||
|
||
func isSubscribedToTags(request *ListenResultRequest, e *execution.Execution) bool { | ||
if len(request.TagFilters) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Len check not needed? if len == 0 the for won't be executed and funcs return true anyway. |
||
return true | ||
} | ||
for _, tag := range request.TagFilters { | ||
if !array.IncludedIn(e.Tags, tag) { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/to listen results with specific tag(s)/to listen to results with the specific tag(s)/