use of com.uber.cadence.GetWorkflowExecutionHistoryResponse in project cadence-client by uber-java.
the class WorkflowExecutionUtils method getInstanceCloseEvent.
/**
* Returns an instance closing event, potentially waiting for workflow to complete.
*/
public static HistoryEvent getInstanceCloseEvent(IWorkflowService service, String domain, WorkflowExecution workflowExecution, long timeout, TimeUnit unit) throws TimeoutException, EntityNotExistsError {
byte[] pageToken = null;
GetWorkflowExecutionHistoryResponse response;
// TODO: Interrupt service long poll call on timeout and on interrupt
long start = System.currentTimeMillis();
HistoryEvent event;
do {
GetWorkflowExecutionHistoryRequest r = new GetWorkflowExecutionHistoryRequest();
r.setDomain(domain);
r.setExecution(workflowExecution);
r.setHistoryEventFilterType(HistoryEventFilterType.CLOSE_EVENT);
r.setNextPageToken(pageToken);
try {
response = Retryer.retryWithResult(retryParameters, () -> service.GetWorkflowExecutionHistory(r));
} catch (EntityNotExistsError e) {
throw e;
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
}
if (timeout != 0 && System.currentTimeMillis() - start > unit.toMillis(timeout)) {
throw new TimeoutException("WorkflowId=" + workflowExecution.getWorkflowId() + ", runId=" + workflowExecution.getRunId() + ", timeout=" + timeout + ", unit=" + unit);
}
pageToken = response.getNextPageToken();
History history = response.getHistory();
if (history != null && history.getEvents().size() > 0) {
event = history.getEvents().get(0);
if (!isWorkflowExecutionCompletedEvent(event)) {
throw new RuntimeException("Last history event is not completion event: " + event);
}
// Workflow called continueAsNew. Start polling the new generation with new runId.
if (event.getEventType() == EventType.WorkflowExecutionContinuedAsNew) {
pageToken = null;
workflowExecution = new WorkflowExecution().setWorkflowId(workflowExecution.getWorkflowId()).setRunId(event.getWorkflowExecutionContinuedAsNewEventAttributes().getNewExecutionRunId());
continue;
}
break;
}
} while (true);
return event;
}
Aggregations