Search in sources :

Example 1 with WorkflowQuery

use of com.uber.cadence.WorkflowQuery in project cadence-client by uber-java.

the class WorkflowWorker method queryWorkflowExecution.

public byte[] queryWorkflowExecution(WorkflowExecution execution, String queryType, byte[] args) throws Exception {
    Iterator<HistoryEvent> history = WorkflowExecutionUtils.getHistory(service, domain, execution);
    DecisionTaskWithHistoryIterator historyIterator = new ReplayDecisionTaskWithHistoryIterator(execution, history);
    WorkflowQuery query = new WorkflowQuery();
    query.setQueryType(queryType).setQueryArgs(args);
    historyIterator.getDecisionTask().setQuery(query);
    DecisionTaskHandler.Result result = handler.handleDecisionTask(historyIterator);
    if (result.getQueryCompleted() != null) {
        RespondQueryTaskCompletedRequest r = result.getQueryCompleted();
        return r.getQueryResult();
    }
    throw new RuntimeException("Query returned wrong response: " + result);
}
Also used : WorkflowQuery(com.uber.cadence.WorkflowQuery) RespondQueryTaskCompletedRequest(com.uber.cadence.RespondQueryTaskCompletedRequest) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 2 with WorkflowQuery

use of com.uber.cadence.WorkflowQuery in project cadence-client by uber-java.

the class GenericWorkflowClientExternalImpl method queryWorkflow.

@Override
public byte[] queryWorkflow(QueryWorkflowParameters queryParameters) {
    QueryWorkflowRequest request = new QueryWorkflowRequest();
    request.setDomain(domain);
    WorkflowExecution execution = new WorkflowExecution();
    execution.setWorkflowId(queryParameters.getWorkflowId()).setRunId(queryParameters.getRunId());
    request.setExecution(execution);
    WorkflowQuery query = new WorkflowQuery();
    query.setQueryArgs(queryParameters.getInput());
    query.setQueryType(queryParameters.getQueryType());
    request.setQuery(query);
    try {
        QueryWorkflowResponse response = service.QueryWorkflow(request);
        return response.getQueryResult();
    } catch (TException e) {
        throw CheckedExceptionWrapper.wrap(e);
    }
}
Also used : TException(org.apache.thrift.TException) WorkflowQuery(com.uber.cadence.WorkflowQuery) QueryWorkflowResponse(com.uber.cadence.QueryWorkflowResponse) WorkflowExecution(com.uber.cadence.WorkflowExecution) QueryWorkflowRequest(com.uber.cadence.QueryWorkflowRequest)

Aggregations

WorkflowQuery (com.uber.cadence.WorkflowQuery)2 HistoryEvent (com.uber.cadence.HistoryEvent)1 QueryWorkflowRequest (com.uber.cadence.QueryWorkflowRequest)1 QueryWorkflowResponse (com.uber.cadence.QueryWorkflowResponse)1 RespondQueryTaskCompletedRequest (com.uber.cadence.RespondQueryTaskCompletedRequest)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 TException (org.apache.thrift.TException)1