temporal
temporal copied to clipboard
How to query all workflows with a particular search parameter
I have below query - I have a object X added to workflowInterface and there is a query method on it , how do query all workflows which have X.variableName = 'value'
List<WorkflowExecutionInfo> workflows = serviceStubs .blockingStub() .listWorkflowExecutions( ListWorkflowExecutionsRequest .newBuilder() .setNamespace(observer.getNamespace()) .setQuery("WorkflowType="MyWorkflow"") .build() ).getExecutionsList();
You can use search attribute to do what you want. First, you need to register your search attribute: https://docs.temporal.io/cloud/tcld/namespace/search-attributes/add/ Then, in your workflow code, you will do something like: UpsertSearchAttribute("MySearchAttributeName", "MyValue")
Then, in your ListWorkflow call, you apply filter like 'MySearchAttributeName = "MyValue"'
@yiminc Can this be automatic? eg: We can directly query the payload passed to the workflow etc in the Web UI
Thanks
You need to 1) register your search attribute (this is a one time job); 2) tag your workflow with your search attribute. This cannot be automated because temporal server don't know about your search attribute. For step 2, if you know the value for your search attribute when you start your workflow (as you mentioned based on input), then you could set SearchAttributes when you start your workflow (it is part of start workflow request)