use of com.uber.cadence.HistoryEvent in project cadence-client by uber-java.
the class WorkflowExecutionUtils method waitForWorkflowInstanceCompletionAcrossGenerations.
/**
* Like {@link #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution,
* long, TimeUnit)} , except will wait for continued generations of the original workflow
* execution too.
*
* @see #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution, long,
* TimeUnit)
*/
public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletionAcrossGenerations(IWorkflowService service, String domain, WorkflowExecution workflowExecution, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, EntityNotExistsError {
WorkflowExecution lastExecutionToRun = workflowExecution;
long millisecondsAtFirstWait = System.currentTimeMillis();
WorkflowExecutionCloseStatus lastExecutionToRunCloseStatus = waitForWorkflowInstanceCompletion(service, domain, lastExecutionToRun, timeout, unit);
// keep waiting if the instance continued as new
while (lastExecutionToRunCloseStatus == WorkflowExecutionCloseStatus.CONTINUED_AS_NEW) {
// get the new execution's information
HistoryEvent closeEvent = getInstanceCloseEvent(service, domain, lastExecutionToRun, timeout, unit);
WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewAttributes = closeEvent.getWorkflowExecutionContinuedAsNewEventAttributes();
WorkflowExecution newGenerationExecution = new WorkflowExecution();
newGenerationExecution.setRunId(continuedAsNewAttributes.getNewExecutionRunId());
newGenerationExecution.setWorkflowId(lastExecutionToRun.getWorkflowId());
// and wait for it
long currentTime = System.currentTimeMillis();
long millisecondsSinceFirstWait = currentTime - millisecondsAtFirstWait;
long timeoutInSecondsForNextWait = unit.toMillis(timeout) - (millisecondsSinceFirstWait / 1000L);
lastExecutionToRunCloseStatus = waitForWorkflowInstanceCompletion(service, domain, newGenerationExecution, timeoutInSecondsForNextWait, TimeUnit.MILLISECONDS);
lastExecutionToRun = newGenerationExecution;
}
return lastExecutionToRunCloseStatus;
}
use of com.uber.cadence.HistoryEvent in project cadence-client by uber-java.
the class WorkflowContext method getWorkflowStartedEventAttributes.
private WorkflowExecutionStartedEventAttributes getWorkflowStartedEventAttributes() {
HistoryEvent firstHistoryEvent = decisionTask.getHistory().getEvents().get(0);
WorkflowExecutionStartedEventAttributes attributes = firstHistoryEvent.getWorkflowExecutionStartedEventAttributes();
return attributes;
}
use of com.uber.cadence.HistoryEvent in project cadence-client by uber-java.
the class StateMachines method completeExternalSignal.
private static void completeExternalSignal(RequestContext ctx, SignalExternalData data, String runId, long notUsed) {
SignalExternalWorkflowExecutionInitiatedEventAttributes initiatedEvent = data.initiatedEvent;
WorkflowExecution signaledExecution = initiatedEvent.getWorkflowExecution().deepCopy().setRunId(runId);
ExternalWorkflowExecutionSignaledEventAttributes a = new ExternalWorkflowExecutionSignaledEventAttributes().setInitiatedEventId(data.initiatedEventId).setWorkflowExecution(signaledExecution).setControl(initiatedEvent.getControl()).setDomain(initiatedEvent.getDomain());
HistoryEvent event = new HistoryEvent().setEventType(EventType.ExternalWorkflowExecutionSignaled).setExternalWorkflowExecutionSignaledEventAttributes(a);
ctx.addEvent(event);
}
use of com.uber.cadence.HistoryEvent in project cadence-client by uber-java.
the class StateMachines method timeoutChildWorkflow.
private static void timeoutChildWorkflow(RequestContext ctx, ChildWorkflowData data, TimeoutType timeoutType, long notUsed) {
StartChildWorkflowExecutionInitiatedEventAttributes ie = data.initiatedEvent;
ChildWorkflowExecutionTimedOutEventAttributes a = new ChildWorkflowExecutionTimedOutEventAttributes().setDomain(ie.getDomain()).setStartedEventId(data.startedEventId).setWorkflowExecution(data.execution).setWorkflowType(ie.getWorkflowType()).setTimeoutType(timeoutType).setInitiatedEventId(data.initiatedEventId);
HistoryEvent event = new HistoryEvent().setEventType(EventType.ChildWorkflowExecutionTimedOut).setChildWorkflowExecutionTimedOutEventAttributes(a);
ctx.addEvent(event);
}
use of com.uber.cadence.HistoryEvent in project cadence-client by uber-java.
the class StateMachines method timeoutWorkflow.
private static void timeoutWorkflow(RequestContext ctx, WorkflowData data, TimeoutType timeoutType, long notUsed) {
WorkflowExecutionTimedOutEventAttributes a = new WorkflowExecutionTimedOutEventAttributes().setTimeoutType(timeoutType);
HistoryEvent event = new HistoryEvent().setEventType(EventType.WorkflowExecutionTimedOut).setWorkflowExecutionTimedOutEventAttributes(a);
ctx.addEvent(event);
}
Aggregations