How do I list all workflows that matches a workflowName
or workflowId
?
While ListOpenWorkflow and ListClosedWorkflow accepts request filters
, ListWorkflow only accepts query
which I assume only work if one is using ElasticSearch as backend.
The following works for me:
c, err := client.NewClient(client.Options{})
if err != nil {
log.Fatalln("Unable to create client", err)
}
defer c.Close()
r, err := c.ListOpenWorkflow(context.Background(), &workflowservice.ListOpenWorkflowExecutionsRequest{
Namespace: "default",
Filters: &workflowservice.ListOpenWorkflowExecutionsRequest_TypeFilter{
TypeFilter: &filter.WorkflowTypeFilter{
Name: "GreetingWorkflow",
},
},
})
Thanks Maxim for the reply. Will ListOpenWorkflowExecutionsRequest
also list closed/completed/terminated/failed workflows? I was wondering if there is a request I can make to fetch all workflows matching a workflowName regardless of it’s state.
Not without ES. You’ll have to make two API calls now. One for closed and one for open.
If you are running with ElasticSearch on backend then you can use ListWorkflowExecution
API with SQL like syntax to provide the filter for your search query. Here are few examples:
List Open Workflow Executions:
./tctl wf list --query "ExecutionStatus=1"
WORKFLOW TYPE | WORKFLOW ID | RUN ID | TASK QUEUE | START TIME | EXECUTION TIME | END TIME
SearchAttributesWorkflow | search_attributes_c9b30359-f4d1-4c40-9bb9-b6929c48e115 | aacdb1e7-ce92-4e6b-9da9-6db8e7c47d8e | search-attributes | 17:30:25 | 17:30:25 | 00:00:00
List all workflow executions for a specific workflow type:
./tctl wf list --query "WorkflowType='SearchAttributesWorkflow'"
WORKFLOW TYPE | WORKFLOW ID | RUN ID | TASK QUEUE | START TIME | EXECUTION TIME | END TIME
SearchAttributesWorkflow | search_attributes_c9b30359-f4d1-4c40-9bb9-b6929c48e115 | aacdb1e7-ce92-4e6b-9da9-6db8e7c47d8e | search-attributes | 17:30:25 | 17:30:25 | 00:00:00
SearchAttributesWorkflow | search_attributes_21b27b32-79b6-4a34-950f-ca7a52b0fed9 | 43f4e415-9f00-42c1-8e44-265c42057609 | search-attributes | 17:30:17 | 17:30:17 | 17:30:19
SearchAttributesWorkflow | search_attributes_5385f67d-e9ee-4531-a187-1c6076b1230e | 3daa6cbd-4bd2-4988-b6f4-5ff8832841ec | search-attributes | 17:16:49 | 17:16:49 | 17:16:51
SearchAttributesWorkflow | search_attributes_af287adf-00c3-4ef6-909b-82b748755e46 | e419a291-6b37-4f5e-a50d-477e20b33b59 | search-attributes | 16:54:06 | 16:54:06 | 17:16:31
List workflow execution with specific type and Id:
./tctl wf list --query "WorkflowType='SearchAttributesWorkflow' and WorkflowId='search_attributes_c9b30359-f4d1-4c40-9bb9-b6929c48e115'"
WORKFLOW TYPE | WORKFLOW ID | RUN ID | TASK QUEUE | START TIME | EXECUTION TIME | END TIME
SearchAttributesWorkflow | search_attributes_c9b30359-f4d1-4c40-9bb9-b6929c48e115 | aacdb1e7-ce92-4e6b-9da9-6db8e7c47d8e | search-attributes | 17:30:25 | 17:30:25 | 00:00:00
If your workflow also provides own searchable attributes like below:
// update search attributes again.
attributes = map[string]interface{}{
"CustomKeywordField": "Update2",
}
_ = workflow.UpsertSearchAttributes(ctx, attributes)
Then you can also provide it as part of filter:
./tctl wf list --query "CustomKeywordField='Update2'" -psa
WORKFLOW TYPE | WORKFLOW ID | RUN ID | TASK QUEUE | START TIME | EXECUTION TIME | END TIME | SEARCH ATTRIBUTES
SearchAttributesWorkflow | search_attributes_c9b30359-f4d1-4c40-9bb9-b6929c48e115 | aacdb1e7-ce92-4e6b-9da9-6db8e7c47d8e | search-attributes | 17:30:25 | 17:30:25 | 00:00:00 | CustomKeywordField=Update2
| | | | | | | CustomIntField=2 CustomDoubleField=3.14
| | | | | | | CustomDatetimeField=2019-01-01T00:00:00-08:00
| | | | | | | CustomBoolField=true
| | | | | | | BinaryChecksums=[db94f4ab9a400098331706e5f5f6bd58]
| | | | | | | CustomStringField=String field is for text. When
| | | | | | | query, it will be tokenized for partial match.
| | | | | | | StringTypeField cannot be used in Order By
SearchAttributesWorkflow | search_attributes_21b27b32-79b6-4a34-950f-ca7a52b0fed9 | 43f4e415-9f00-42c1-8e44-265c42057609 | search-attributes | 17:30:17 | 17:30:17 | 17:30:19 | CustomDatetimeField=2019-01-01T00:00:00-08:00
| | | | | | | CustomBoolField=true
| | | | | | | BinaryChecksums=[db94f4ab9a400098331706e5f5f6bd58]
| | | | | | | CustomStringField=String field is for text.
| | | | | | | When query, it will be tokenized for partial
| | | | | | | match. StringTypeField cannot be used in Order
| | | | | | | By CustomKeywordField=Update2 CustomIntField=2
| | | | | | | CustomDoubleField=3.14
SearchAttributesWorkflow | search_attributes_5385f67d-e9ee-4531-a187-1c6076b1230e | 3daa6cbd-4bd2-4988-b6f4-5ff8832841ec | search-attributes | 17:16:49 | 17:16:49 | 17:16:51 | BinaryChecksums=[db94f4ab9a400098331706e5f5f6bd58]
| | | | | | | CustomStringField=String field is for
| | | | | | | text. When query, it will be tokenized for
| | | | | | | partial match. StringTypeField cannot be
| | | | | | | used in Order By CustomKeywordField=Update2
| | | | | | | CustomIntField=2 CustomDoubleField=3.14
| | | | | | | CustomDatetimeField=2019-01-01T00:00:00-08:00
| | | | | | | CustomBoolField=true
SearchAttributesWorkflow | search_attributes_af287adf-00c3-4ef6-909b-82b748755e46 | e419a291-6b37-4f5e-a50d-477e20b33b59 | search-attributes | 16:54:06 | 16:54:06 | 17:16:31 | BinaryChecksums=[db94f4ab9a400098331706e5f5f6bd58]
| | | | | | | CustomStringField=String field is for
| | | | | | | text. When query, it will be tokenized for
| | | | | | | partial match. StringTypeField cannot be
| | | | | | | used in Order By CustomKeywordField=Update2
| | | | | | | CustomIntField=2 CustomDoubleField=3.14
| | | | | | | CustomDatetimeField=2019-01-01T00:00:00-08:00
| | | | | | | CustomBoolField=true
How would you specify multiple Workflow Types to filter by? Or would that have to be separate request?