Search in sources :

Example 1 with ActivityNotExistsException

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

the class ActivityExecutionContextImpl method recordActivityHeartbeat.

/**
 * @throws CancellationException
 * @see ActivityExecutionContext#recordActivityHeartbeat(Object)
 */
@Override
public void recordActivityHeartbeat(Object details) throws ActivityCompletionException {
    // TODO: call service with the specified minimal interval (through @ActivityExecutionOptions)
    // allowing more frequent calls of this method.
    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()) {
            throw new ActivityCancelledException(task);
        }
    } catch (EntityNotExistsError e) {
        throw new ActivityNotExistsException(task, e);
    } catch (BadRequestError e) {
        throw new ActivityCompletionFailureException(task, e);
    } catch (TException e) {
        log.warn("Failure heartbeating on activityID=" + task.getActivityId() + " of Workflow=" + task.getWorkflowExecution(), e);
    // Not rethrowing to not fail activity implementation on intermittent connection or Cadence errors.
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) ActivityCancelledException(com.uber.cadence.client.ActivityCancelledException) RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) RecordActivityTaskHeartbeatRequest(com.uber.cadence.RecordActivityTaskHeartbeatRequest) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError)

Example 2 with ActivityNotExistsException

use of com.uber.cadence.client.ActivityNotExistsException 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)

Example 3 with ActivityNotExistsException

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

Example 4 with ActivityNotExistsException

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

Aggregations

EntityNotExistsError (com.uber.cadence.EntityNotExistsError)4 ActivityCompletionFailureException (com.uber.cadence.client.ActivityCompletionFailureException)4 ActivityNotExistsException (com.uber.cadence.client.ActivityNotExistsException)4 TException (org.apache.thrift.TException)4 RecordActivityTaskHeartbeatRequest (com.uber.cadence.RecordActivityTaskHeartbeatRequest)2 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)2 ActivityCancelledException (com.uber.cadence.client.ActivityCancelledException)2 BadRequestError (com.uber.cadence.BadRequestError)1 RespondActivityTaskCompletedByIDRequest (com.uber.cadence.RespondActivityTaskCompletedByIDRequest)1 RespondActivityTaskCompletedRequest (com.uber.cadence.RespondActivityTaskCompletedRequest)1 RespondActivityTaskFailedByIDRequest (com.uber.cadence.RespondActivityTaskFailedByIDRequest)1 RespondActivityTaskFailedRequest (com.uber.cadence.RespondActivityTaskFailedRequest)1