use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError 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 {
RpcRetryer.retry(() -> service.RespondActivityTaskCompleted(request));
metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (WorkflowExecutionAlreadyCompletedError 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);
metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_BY_ID_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (WorkflowExecutionAlreadyCompletedError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(activityId, e);
}
}
}
use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError 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 {
RpcRetryer.retry(() -> service.RespondActivityTaskFailed(request));
metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (WorkflowExecutionAlreadyCompletedError 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 {
RpcRetryer.retry(() -> service.RespondActivityTaskFailedByID(request));
metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_BY_ID_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
} catch (WorkflowExecutionAlreadyCompletedError e) {
throw new ActivityNotExistsException(e);
} catch (TException e) {
throw new ActivityCompletionFailureException(activityId, e);
}
}
}
use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError 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 (WorkflowExecutionAlreadyCompletedError 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.");
}
}
use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError in project cadence-client by uber-java.
the class TestWorkflowMutableStateImpl method processCancelWorkflowExecution.
private void processCancelWorkflowExecution(RequestContext ctx, CancelWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId) throws InternalServiceError, BadRequestError {
workflow.action(StateMachines.Action.CANCEL, ctx, d, decisionTaskCompletedId);
if (parent.isPresent()) {
// unlocked by the parent
ctx.lockTimer();
ChildWorkflowExecutionCanceledEventAttributes a = new ChildWorkflowExecutionCanceledEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setDetails(d.getDetails()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution()).setWorkflowType(startRequest.getWorkflowType());
ForkJoinPool.commonPool().execute(() -> {
try {
parent.get().childWorkflowCanceled(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
// Parent might already close
} 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 TestWorkflowMutableStateImpl method addActivityRetryTimer.
private void addActivityRetryTimer(RequestContext ctx, StateMachine<ActivityTaskData> activity) {
ActivityTaskData data = activity.getData();
int attempt = data.retryState.getAttempt();
ctx.addTimer(data.nextBackoffIntervalSeconds, () -> {
// Timers are not removed, so skip if it is not for this attempt.
if (activity.getState() != State.INITIATED && data.retryState.getAttempt() != attempt) {
return;
}
selfAdvancingTimer.lockTimeSkipping("activityRetryTimer " + activity.getData().scheduledEvent.getActivityId());
boolean unlockTimer = false;
try {
update(ctx1 -> ctx1.addActivityTask(data.activityTask));
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
unlockTimer = true;
// Expected as timers are not removed
} catch (Exception e) {
unlockTimer = true;
// Cannot fail to timer threads
log.error("Failure trying to add task for an activity retry", e);
} finally {
if (unlockTimer) {
// Allow time skipping when waiting for an activity retry
selfAdvancingTimer.unlockTimeSkipping("activityRetryTimer " + activity.getData().scheduledEvent.getActivityId());
}
}
}, "Activity Retry");
}
Aggregations