use of com.uber.cadence.RecordActivityTaskHeartbeatResponse 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.
}
}
use of com.uber.cadence.RecordActivityTaskHeartbeatResponse in project cadence-client by uber-java.
the class TestWorkflowMutableStateImpl method heartbeatActivityTask.
@Override
public RecordActivityTaskHeartbeatResponse heartbeatActivityTask(String activityId, RecordActivityTaskHeartbeatRequest request) throws InternalServiceError, EntityNotExistsError, BadRequestError {
RecordActivityTaskHeartbeatResponse result = new RecordActivityTaskHeartbeatResponse();
try {
update(ctx -> {
StateMachine<ActivityTaskData> activity = getActivity(activityId);
activity.action(StateMachines.Action.UPDATE, ctx, request, 0);
if (activity.getState() == StateMachines.State.CANCELLATION_REQUESTED) {
result.setCancelRequested(true);
}
ActivityTaskData data = activity.getData();
data.lastHeartbeatTime = clock.getAsLong();
int startToCloseTimeout = data.scheduledEvent.getStartToCloseTimeoutSeconds();
int heartbeatTimeout = data.scheduledEvent.getHeartbeatTimeoutSeconds();
updateHeartbeatTimer(ctx, activityId, activity, startToCloseTimeout, heartbeatTimeout);
});
} catch (InternalServiceError | EntityNotExistsError e) {
throw e;
} catch (Exception e) {
throw new InternalServiceError(Throwables.getStackTraceAsString(e));
}
return result;
}
use of com.uber.cadence.RecordActivityTaskHeartbeatResponse 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