use of com.uber.cadence.EntityNotExistsError 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;
}
use of com.uber.cadence.EntityNotExistsError in project cadence-client by uber-java.
the class ManualActivityCompletionClientImpl method fail.
@Override
public void fail(Throwable failure) {
if (failure == null) {
throw new IllegalArgumentException("null failure");
}
// When converting failures reason is class name, details are serialized exception.
if (taskToken != null) {
RespondActivityTaskFailedRequest request = new RespondActivityTaskFailedRequest();
request.setReason(failure.getClass().getName());
request.setDetails(dataConverter.toData(failure));
request.setTaskToken(taskToken);
try {
service.RespondActivityTaskFailed(request);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(e);
}
} else {
RespondActivityTaskFailedByIDRequest request = new RespondActivityTaskFailedByIDRequest();
request.setReason(failure.getClass().getName());
request.setDetails(dataConverter.toData(failure));
request.setDomain(domain);
request.setWorkflowID(execution.getWorkflowId());
request.setRunID(execution.getRunId());
try {
service.RespondActivityTaskFailedByID(request);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(activityId, e);
}
}
}
use of com.uber.cadence.EntityNotExistsError in project cadence-client by uber-java.
the class ManualActivityCompletionClientImpl method complete.
@Override
public void complete(Object result) {
if (taskToken != null) {
RespondActivityTaskCompletedRequest request = new RespondActivityTaskCompletedRequest();
byte[] convertedResult = dataConverter.toData(result);
request.setResult(convertedResult);
request.setTaskToken(taskToken);
try {
service.RespondActivityTaskCompleted(request);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(e);
}
} else {
if (activityId == null) {
throw new IllegalArgumentException("Either activity id or task token are required");
}
RespondActivityTaskCompletedByIDRequest request = new RespondActivityTaskCompletedByIDRequest();
request.setActivityID(activityId);
byte[] convertedResult = dataConverter.toData(result);
request.setResult(convertedResult);
request.setDomain(domain);
request.setWorkflowID(execution.getWorkflowId());
request.setRunID(execution.getRunId());
try {
service.RespondActivityTaskCompletedByID(request);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(activityId, e);
}
}
}
use of com.uber.cadence.EntityNotExistsError in project cadence-client by uber-java.
the class ManualActivityCompletionClientImpl method recordHeartbeat.
@Override
public void recordHeartbeat(Object details) throws CancellationException {
if (taskToken != null) {
RecordActivityTaskHeartbeatRequest request = new RecordActivityTaskHeartbeatRequest();
request.setDetails(dataConverter.toData(details));
request.setTaskToken(taskToken);
RecordActivityTaskHeartbeatResponse status = null;
try {
status = service.RecordActivityTaskHeartbeat(request);
if (status.isCancelRequested()) {
throw new ActivityCancelledException();
}
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(e);
}
} else {
throw new UnsupportedOperationException("Heartbeating by id is not implemented by Cadence service yet.");
}
}
Aggregations