use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError in project cadence-client by uber-java.
the class TestWorkflowMutableStateImpl method reportWorkflowTimeoutToParent.
private void reportWorkflowTimeoutToParent(RequestContext ctx) {
if (!parent.isPresent()) {
return;
}
try {
ChildWorkflowExecutionTimedOutEventAttributes a = new ChildWorkflowExecutionTimedOutEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setTimeoutType(TimeoutType.START_TO_CLOSE).setWorkflowType(startRequest.getWorkflowType()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution());
parent.get().childWorkflowTimedOut(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
// Parent might already close
} catch (BadRequestError | InternalServiceError e) {
log.error("Failure reporting child timing out", e);
}
}
use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError in project cadence-client by uber-java.
the class TestWorkflowMutableStateImpl method startWorkflow.
@Override
public void startWorkflow(boolean continuedAsNew, Optional<SignalWorkflowExecutionRequest> signalWithStartSignal) throws InternalServiceError, BadRequestError {
try {
update(ctx -> {
workflow.action(StateMachines.Action.START, ctx, startRequest, 0);
if (signalWithStartSignal.isPresent()) {
addExecutionSignaledEvent(ctx, signalWithStartSignal.get());
}
int backoffStartIntervalInSeconds = workflow.getData().backoffStartIntervalInSeconds;
if (backoffStartIntervalInSeconds > 0) {
ctx.addTimer(backoffStartIntervalInSeconds, () -> {
try {
update(ctx1 -> scheduleDecision(ctx1));
} catch (EntityNotExistsError e) {
// Expected as timers are not removed
} catch (Exception e) {
// Cannot fail to timer threads
log.error("Failure trying to add task for an delayed workflow retry", e);
}
}, "delayedFirstDecision");
} else {
scheduleDecision(ctx);
}
int executionTimeoutTimerDelay = startRequest.getExecutionStartToCloseTimeoutSeconds();
if (backoffStartIntervalInSeconds > 0) {
executionTimeoutTimerDelay = executionTimeoutTimerDelay + backoffStartIntervalInSeconds;
}
ctx.addTimer(executionTimeoutTimerDelay, this::timeoutWorkflow, "workflow execution timeout");
});
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
throw new InternalServiceError(Throwables.getStackTraceAsString(e));
}
if (!continuedAsNew && parent.isPresent()) {
ChildWorkflowExecutionStartedEventAttributes a = new ChildWorkflowExecutionStartedEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setWorkflowExecution(getExecutionId().getExecution()).setDomain(getExecutionId().getDomain()).setWorkflowType(startRequest.getWorkflowType());
ForkJoinPool.commonPool().execute(() -> {
try {
parent.get().childWorkflowStarted(a);
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
// Not a problem. Parent might just close by now.
} catch (BadRequestError | InternalServiceError e) {
log.error("Failure reporting child completion", e);
}
});
}
}
use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError in project cadence-client by uber-java.
the class WorkflowStubImpl method mapToWorkflowFailureException.
private <R> R mapToWorkflowFailureException(Exception failure, @SuppressWarnings("unused") Class<R> returnType) {
failure = CheckedExceptionWrapper.unwrap(failure);
Class<Throwable> detailsClass;
if (failure instanceof WorkflowExecutionFailedException) {
WorkflowExecutionFailedException executionFailed = (WorkflowExecutionFailedException) failure;
try {
@SuppressWarnings("unchecked") Class<Throwable> dc = (Class<Throwable>) Class.forName(executionFailed.getReason());
detailsClass = dc;
} catch (Exception e) {
RuntimeException ee = new RuntimeException("Couldn't deserialize failure cause " + "as the reason field is expected to contain an exception class name", executionFailed);
throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), ee);
}
Throwable cause = dataConverter.fromData(executionFailed.getDetails(), detailsClass, detailsClass);
throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
} else if (failure instanceof EntityNotExistsError) {
throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
} else if (failure instanceof WorkflowExecutionAlreadyCompletedError) {
throw new WorkflowAlreadyCompletedException(execution.get(), workflowType, failure.getMessage());
} else if (failure instanceof CancellationException) {
throw (CancellationException) failure;
} else if (failure instanceof WorkflowException) {
throw (WorkflowException) failure;
} else {
throw new WorkflowServiceException(execution.get(), workflowType, failure);
}
}
use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError in project cadence-client by uber-java.
the class ActivityExecutionContextImpl method sendHeartbeatRequest.
private void sendHeartbeatRequest(Object details) throws TException {
RecordActivityTaskHeartbeatRequest r = new RecordActivityTaskHeartbeatRequest();
r.setTaskToken(task.getTaskToken());
byte[] serialized = dataConverter.toData(details);
r.setDetails(serialized);
RecordActivityTaskHeartbeatResponse status;
try {
status = service.RecordActivityTaskHeartbeat(r);
if (status.isCancelRequested()) {
lastException = new ActivityCancelledException(task);
} else {
lastException = null;
}
} catch (EntityNotExistsError e) {
lastException = new ActivityNotExistsException(task, e);
} catch (WorkflowExecutionAlreadyCompletedError e) {
throw new ActivityNotExistsException(task, e);
} catch (BadRequestError e) {
lastException = new ActivityCompletionFailureException(task, e);
}
}
Aggregations