use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.
the class ActivityStateMachine method notifyCanceled.
private void notifyCanceled() {
Failure canceledFailure = Failure.newBuilder().setSource(JAVA_SDK).setCanceledFailureInfo(CanceledFailureInfo.getDefaultInstance()).build();
ActivityFailureInfo activityFailureInfo = ActivityFailureInfo.newBuilder().setActivityId(activityId).setActivityType(activityType).setIdentity("workflow").setScheduledEventId(getInitialCommandEventId()).setStartedEventId(startedCommandEventId).build();
Failure failure = Failure.newBuilder().setActivityFailureInfo(activityFailureInfo).setCause(canceledFailure).setMessage("Activity canceled").build();
completionCallback.apply(Optional.empty(), failure);
}
use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.
the class ActivityStateMachine method notifyCancellationFromEvent.
private void notifyCancellationFromEvent() {
if (cancellationType == ActivityCancellationType.WAIT_CANCELLATION_COMPLETED) {
ActivityTaskCanceledEventAttributes canceledAttr = currentEvent.getActivityTaskCanceledEventAttributes();
Failure canceledFailure = Failure.newBuilder().setSource(JAVA_SDK).setCanceledFailureInfo(CanceledFailureInfo.newBuilder().setDetails(canceledAttr.getDetails())).build();
ActivityFailureInfo failureInfo = ActivityFailureInfo.newBuilder().setActivityId(activityId).setActivityType(activityType).setScheduledEventId(canceledAttr.getScheduledEventId()).setStartedEventId(canceledAttr.getStartedEventId()).build();
Failure failure = Failure.newBuilder().setActivityFailureInfo(failureInfo).setCause(canceledFailure).setMessage("Activity canceled").build();
completionCallback.apply(Optional.empty(), failure);
}
}
use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.
the class TestWorkflowService method startWorkflowExecutionImpl.
StartWorkflowExecutionResponse startWorkflowExecutionImpl(StartWorkflowExecutionRequest startRequest, Duration backoffStartInterval, Optional<TestWorkflowMutableState> parent, OptionalLong parentChildInitiatedEventId, Optional<SignalWorkflowExecutionRequest> signalWithStartSignal) {
String requestWorkflowId = requireNotNull("WorkflowId", startRequest.getWorkflowId());
String namespace = requireNotNull("Namespace", startRequest.getNamespace());
WorkflowId workflowId = new WorkflowId(namespace, requestWorkflowId);
TestWorkflowMutableState existing;
lock.lock();
try {
existing = executionsByWorkflowId.get(workflowId);
if (existing != null) {
WorkflowExecutionStatus status = existing.getWorkflowExecutionStatus();
WorkflowIdReusePolicy policy = startRequest.getWorkflowIdReusePolicy();
if (status == WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_RUNNING || policy == WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) {
return throwDuplicatedWorkflow(startRequest, existing);
}
if (policy == WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY && (status == WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED || status == WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW)) {
return throwDuplicatedWorkflow(startRequest, existing);
}
}
Optional<TestServiceRetryState> retryState;
Optional<Failure> lastFailure = Optional.empty();
if (startRequest.hasRetryPolicy()) {
Duration expirationInterval = ProtobufTimeUtils.toJavaDuration(startRequest.getWorkflowExecutionTimeout());
retryState = newRetryStateLocked(startRequest.getRetryPolicy(), expirationInterval);
if (retryState.isPresent()) {
lastFailure = retryState.get().getPreviousRunFailure();
}
} else {
retryState = Optional.empty();
}
return startWorkflowExecutionNoRunningCheckLocked(startRequest, UUID.randomUUID().toString(), Optional.empty(), retryState, backoffStartInterval, null, lastFailure, parent, parentChildInitiatedEventId, signalWithStartSignal, workflowId);
} finally {
lock.unlock();
}
}
use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.
the class StateMachines method timeoutActivityTask.
private static State timeoutActivityTask(RequestContext ctx, ActivityTaskData data, TimeoutType timeoutType, long notUsed) {
// ScheduleToStart (queue timeout) is not retryable. Instead of the retry, a customer should set
// a larger ScheduleToStart timeout.
RetryState retryState;
if (timeoutType != TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_START) {
retryState = attemptActivityRetry(ctx, Optional.empty(), data);
if (retryState == RetryState.RETRY_STATE_IN_PROGRESS) {
return INITIATED;
}
} else {
retryState = RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE;
}
Failure failure;
if (timeoutType == TimeoutType.TIMEOUT_TYPE_HEARTBEAT || timeoutType == TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE) {
failure = newTimeoutFailure(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE, Optional.ofNullable(data.heartbeatDetails), Optional.of(newTimeoutFailure(timeoutType, Optional.empty(), Optional.empty())));
} else {
failure = newTimeoutFailure(timeoutType, Optional.ofNullable(data.heartbeatDetails), Optional.empty());
}
ActivityTaskTimedOutEventAttributes.Builder a = ActivityTaskTimedOutEventAttributes.newBuilder().setScheduledEventId(data.scheduledEventId).setRetryState(retryState).setStartedEventId(data.startedEventId).setFailure(failure);
HistoryEvent event = HistoryEvent.newBuilder().setEventType(EventType.EVENT_TYPE_ACTIVITY_TASK_TIMED_OUT).setActivityTaskTimedOutEventAttributes(a).build();
ctx.addEvent(event);
return TIMED_OUT;
}
use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.
the class TestWorkflowService method continueAsNew.
/**
* Creates next run of a workflow execution
*
* @return RunId
*/
public String continueAsNew(StartWorkflowExecutionRequest previousRunStartRequest, WorkflowExecutionContinuedAsNewEventAttributes a, Optional<TestServiceRetryState> retryState, String identity, ExecutionId executionId, Optional<TestWorkflowMutableState> parent, OptionalLong parentChildInitiatedEventId) {
StartWorkflowExecutionRequest.Builder startRequestBuilder = StartWorkflowExecutionRequest.newBuilder().setRequestId(UUID.randomUUID().toString()).setWorkflowType(a.getWorkflowType()).setWorkflowRunTimeout(a.getWorkflowRunTimeout()).setWorkflowTaskTimeout(a.getWorkflowTaskTimeout()).setNamespace(executionId.getNamespace()).setTaskQueue(a.getTaskQueue()).setWorkflowId(executionId.getWorkflowId().getWorkflowId()).setWorkflowIdReusePolicy(previousRunStartRequest.getWorkflowIdReusePolicy()).setIdentity(identity).setCronSchedule(previousRunStartRequest.getCronSchedule());
if (previousRunStartRequest.hasRetryPolicy()) {
startRequestBuilder.setRetryPolicy(previousRunStartRequest.getRetryPolicy());
}
if (a.hasInput()) {
startRequestBuilder.setInput(a.getInput());
}
if (a.hasHeader()) {
startRequestBuilder.setHeader(a.getHeader());
}
StartWorkflowExecutionRequest startRequest = startRequestBuilder.build();
lock.lock();
Optional<Failure> lastFail = a.hasFailure() ? Optional.of(a.getFailure()) : retryState.flatMap(TestServiceRetryState::getPreviousRunFailure);
try {
StartWorkflowExecutionResponse response = startWorkflowExecutionNoRunningCheckLocked(startRequest, a.getNewExecutionRunId(), Optional.of(executionId.getExecution().getRunId()), retryState, ProtobufTimeUtils.toJavaDuration(a.getBackoffStartInterval()), a.getLastCompletionResult(), lastFail, parent, parentChildInitiatedEventId, Optional.empty(), executionId.getWorkflowId());
return response.getRunId();
} finally {
lock.unlock();
}
}
Aggregations