Search in sources :

Example 1 with RespondActivityTaskFailedRequest

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

the class POJOActivityTaskHandler method mapToActivityFailure.

private ActivityTaskHandler.Result mapToActivityFailure(ActivityTask task, Throwable failure) {
    if (failure instanceof Error) {
        throw (Error) failure;
    }
    if (failure instanceof ActivityCancelledException) {
        throw new CancellationException(failure.getMessage());
    }
    RespondActivityTaskFailedRequest result = new RespondActivityTaskFailedRequest();
    failure = CheckedExceptionWrapper.unwrap((Exception) failure);
    result.setReason(failure.getClass().getName());
    result.setDetails(dataConverter.toData(failure));
    return new ActivityTaskHandler.Result(null, result, null, null);
}
Also used : ActivityCancelledException(com.uber.cadence.client.ActivityCancelledException) CancellationException(java.util.concurrent.CancellationException) ActivityCancelledException(com.uber.cadence.client.ActivityCancelledException) CancellationException(java.util.concurrent.CancellationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RespondActivityTaskFailedRequest(com.uber.cadence.RespondActivityTaskFailedRequest)

Example 2 with RespondActivityTaskFailedRequest

use of com.uber.cadence.RespondActivityTaskFailedRequest 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);
        }
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) RespondActivityTaskFailedByIDRequest(com.uber.cadence.RespondActivityTaskFailedByIDRequest) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) RespondActivityTaskFailedRequest(com.uber.cadence.RespondActivityTaskFailedRequest)

Aggregations

RespondActivityTaskFailedRequest (com.uber.cadence.RespondActivityTaskFailedRequest)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 RespondActivityTaskFailedByIDRequest (com.uber.cadence.RespondActivityTaskFailedByIDRequest)1 ActivityCancelledException (com.uber.cadence.client.ActivityCancelledException)1 ActivityCompletionFailureException (com.uber.cadence.client.ActivityCompletionFailureException)1 ActivityNotExistsException (com.uber.cadence.client.ActivityNotExistsException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CancellationException (java.util.concurrent.CancellationException)1 TException (org.apache.thrift.TException)1