Interface ReplayWorkflowContext
-
- All Superinterfaces:
ReplayAware
public interface ReplayWorkflowContext extends ReplayAware
Represents the context for workflow. Should only be used within the scope of workflow definition code, meaning any code which is not part of activity implementations.TODO(maxim): Get rid of any Exceptions in the callbacks. They should only return Failure.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
continueAsNewOnCompletion(io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes attributes)
long
currentTimeMillis()
int
getAttempt()
java.util.List<ContextPropagator>
getContextPropagators()
io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes
getContinueAsNewOnCompletion()
When these attributes are present upon completion of the workflow code the ContinueAsNew command is emitted instead of the workflow completion.java.util.Optional<java.lang.String>
getContinuedExecutionRunId()
RunId of the first run in the continue-as-new chain.java.lang.String
getCronSchedule()
boolean
getEnableLoggingInReplay()
io.temporal.api.common.v1.Payload
getMemo(java.lang.String key)
com.uber.m3.tally.Scope
getMetricsScope()
java.lang.String
getNamespace()
Workflow namespace.io.temporal.api.common.v1.WorkflowExecution
getParentWorkflowExecution()
java.util.Map<java.lang.String,java.lang.Object>
getPropagatedContexts()
Returns all current contexts being propagated by aContextPropagator
.java.lang.String
getRunId()
long
getRunStartedTimestampMillis()
io.temporal.api.common.v1.SearchAttributes
getSearchAttributes()
java.lang.String
getTaskQueue()
Workflow task queue name.void
getVersion(java.lang.String changeId, int minSupported, int maxSupported, Functions.Proc2<java.lang.Integer,java.lang.RuntimeException> callback)
GetVersion is used to safely perform backwards incompatible changes to workflow definitions.io.temporal.api.common.v1.WorkflowExecution
getWorkflowExecution()
java.time.Duration
getWorkflowExecutionTimeout()
java.lang.String
getWorkflowId()
java.time.Duration
getWorkflowRunTimeout()
java.time.Duration
getWorkflowTaskTimeout()
io.temporal.api.common.v1.WorkflowType
getWorkflowType()
boolean
isCancelRequested()
Is cancel of the workflow requested.void
mutableSideEffect(java.lang.String id, Functions.Func1<java.util.Optional<io.temporal.api.common.v1.Payloads>,java.util.Optional<io.temporal.api.common.v1.Payloads>> func, Functions.Proc1<java.util.Optional<io.temporal.api.common.v1.Payloads>> callback)
mutableSideEffect
is similar tosideEffect
in allowing calls of non-deterministic functions from workflow code.java.util.Random
newRandom()
Replay safe random.Functions.Proc1<java.lang.RuntimeException>
newTimer(java.time.Duration delay, Functions.Proc1<java.lang.RuntimeException> callback)
Create a Value that becomes ready after the specified delay.java.util.UUID
randomUUID()
void
requestCancelExternalWorkflowExecution(io.temporal.api.common.v1.WorkflowExecution execution, Functions.Proc2<java.lang.Void,java.lang.RuntimeException> callback)
Request cancellation of a workflow execution by WorkflowId and optionally RunId.Functions.Proc1<java.lang.Exception>
scheduleActivityTask(ExecuteActivityParameters parameters, Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,io.temporal.api.failure.v1.Failure> callback)
Requests an activity execution.Functions.Proc
scheduleLocalActivityTask(ExecuteLocalActivityParameters parameters, Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,io.temporal.api.failure.v1.Failure> callback)
void
sideEffect(Functions.Func<java.util.Optional<io.temporal.api.common.v1.Payloads>> func, Functions.Proc1<java.util.Optional<io.temporal.api.common.v1.Payloads>> callback)
Executes the provided function once, records its result into the workflow history.Functions.Proc1<java.lang.Exception>
signalExternalWorkflowExecution(io.temporal.api.command.v1.SignalExternalWorkflowExecutionCommandAttributes.Builder attributes, Functions.Proc2<java.lang.Void,io.temporal.api.failure.v1.Failure> callback)
Signal a workflow execution by WorkflowId and optionally RunId.Functions.Proc1<java.lang.Exception>
startChildWorkflow(StartChildWorkflowExecutionParameters parameters, Functions.Proc1<io.temporal.api.common.v1.WorkflowExecution> executionCallback, Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,java.lang.Exception> callback)
Start child workflow.void
upsertSearchAttributes(io.temporal.api.common.v1.SearchAttributes searchAttributes)
Updates or inserts search attributes used to index workflows.-
Methods inherited from interface io.temporal.internal.replay.ReplayAware
isReplaying
-
-
-
-
Method Detail
-
getWorkflowExecution
io.temporal.api.common.v1.WorkflowExecution getWorkflowExecution()
-
getParentWorkflowExecution
io.temporal.api.common.v1.WorkflowExecution getParentWorkflowExecution()
-
getWorkflowType
io.temporal.api.common.v1.WorkflowType getWorkflowType()
-
isCancelRequested
boolean isCancelRequested()
Is cancel of the workflow requested.
-
getContinueAsNewOnCompletion
io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes getContinueAsNewOnCompletion()
When these attributes are present upon completion of the workflow code the ContinueAsNew command is emitted instead of the workflow completion.
-
getContinuedExecutionRunId
java.util.Optional<java.lang.String> getContinuedExecutionRunId()
RunId of the first run in the continue-as-new chain. Empty if this workflow never called continue as new.
-
getTaskQueue
java.lang.String getTaskQueue()
Workflow task queue name.
-
getNamespace
java.lang.String getNamespace()
Workflow namespace.
-
getWorkflowId
java.lang.String getWorkflowId()
-
getRunId
java.lang.String getRunId()
-
getWorkflowRunTimeout
java.time.Duration getWorkflowRunTimeout()
-
getWorkflowExecutionTimeout
java.time.Duration getWorkflowExecutionTimeout()
-
getRunStartedTimestampMillis
long getRunStartedTimestampMillis()
-
getWorkflowTaskTimeout
java.time.Duration getWorkflowTaskTimeout()
-
getMemo
io.temporal.api.common.v1.Payload getMemo(java.lang.String key)
-
getSearchAttributes
@Nullable io.temporal.api.common.v1.SearchAttributes getSearchAttributes()
- Returns:
- search attributes as a non-deserialized protobuf, null if empty
-
getPropagatedContexts
java.util.Map<java.lang.String,java.lang.Object> getPropagatedContexts()
Returns all current contexts being propagated by aContextPropagator
. The key is theContextPropagator.getName()
and the value is the object returned byContextPropagator.getCurrentContext()
-
getContextPropagators
java.util.List<ContextPropagator> getContextPropagators()
- Returns:
- the set of configured context propagators
-
scheduleActivityTask
Functions.Proc1<java.lang.Exception> scheduleActivityTask(ExecuteActivityParameters parameters, Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,io.temporal.api.failure.v1.Failure> callback)
Requests an activity execution.- Parameters:
parameters
- An object which encapsulates all the information required to schedule an activity for executioncallback
- Callback that is called upon activity completion or failure.- Returns:
- cancellation handle. Invoke
Functions.Proc1.apply(Object)
to cancel activity task.
-
scheduleLocalActivityTask
Functions.Proc scheduleLocalActivityTask(ExecuteLocalActivityParameters parameters, Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,io.temporal.api.failure.v1.Failure> callback)
-
startChildWorkflow
Functions.Proc1<java.lang.Exception> startChildWorkflow(StartChildWorkflowExecutionParameters parameters, Functions.Proc1<io.temporal.api.common.v1.WorkflowExecution> executionCallback, Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,java.lang.Exception> callback)
Start child workflow.- Parameters:
parameters
- An object which encapsulates all the information required to schedule a child workflow for executioncallback
- Callback that is called upon child workflow completion or failure.- Returns:
- cancellation handle. Invoke
Functions.Proc1.apply(Object)
to cancel activity task.
-
signalExternalWorkflowExecution
Functions.Proc1<java.lang.Exception> signalExternalWorkflowExecution(io.temporal.api.command.v1.SignalExternalWorkflowExecutionCommandAttributes.Builder attributes, Functions.Proc2<java.lang.Void,io.temporal.api.failure.v1.Failure> callback)
Signal a workflow execution by WorkflowId and optionally RunId.- Parameters:
attributes
- signal informationcallback
- callback notified about the operation result- Returns:
- cancellation handler that should be calle to cancel the operation.
-
requestCancelExternalWorkflowExecution
void requestCancelExternalWorkflowExecution(io.temporal.api.common.v1.WorkflowExecution execution, Functions.Proc2<java.lang.Void,java.lang.RuntimeException> callback)
Request cancellation of a workflow execution by WorkflowId and optionally RunId.- Parameters:
execution
- contains WorkflowId and optional RunId of the workflow to send request to.callback
- callback notified about the operation result
-
continueAsNewOnCompletion
void continueAsNewOnCompletion(io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes attributes)
-
currentTimeMillis
long currentTimeMillis()
- Returns:
- time of the
PollWorkflowTaskQueueResponse
start event of the workflow task being processed or replayed.
-
newTimer
Functions.Proc1<java.lang.RuntimeException> newTimer(java.time.Duration delay, Functions.Proc1<java.lang.RuntimeException> callback)
Create a Value that becomes ready after the specified delay.- Parameters:
delay
- time-interval after which the Value becomes ready.callback
- Callback that is called with null parameter after the specified delay. CanceledException is passed as a parameter in case of a cancellation.- Returns:
- cancellation handle. Invoke
Functions.Proc1.apply(Object)
to cancel timer.
-
sideEffect
void sideEffect(Functions.Func<java.util.Optional<io.temporal.api.common.v1.Payloads>> func, Functions.Proc1<java.util.Optional<io.temporal.api.common.v1.Payloads>> callback)
Executes the provided function once, records its result into the workflow history. The recorded result on history will be returned without executing the provided function during replay. This guarantees the deterministic requirement for workflow as the exact same result will be returned in replay. Common use case is to run some short non-deterministic code in workflow, like getting random number or new UUID. The only way to fail SideEffect is to throwError
which causes workflow task failure. The workflow task after timeout is rescheduled and re-executed giving SideEffect another chance to succeed. UsescheduleLocalActivityTask(ExecuteLocalActivityParameters, Functions.Proc2)
for executing operations that rely on non-global dependencies and can fail.- Parameters:
func
- function that is called once to return a value.callback
- function that accepts the result of the side effect.
-
mutableSideEffect
void mutableSideEffect(java.lang.String id, Functions.Func1<java.util.Optional<io.temporal.api.common.v1.Payloads>,java.util.Optional<io.temporal.api.common.v1.Payloads>> func, Functions.Proc1<java.util.Optional<io.temporal.api.common.v1.Payloads>> callback)
mutableSideEffect
is similar tosideEffect
in allowing calls of non-deterministic functions from workflow code.The difference between
mutableSideEffect
andsideEffect
is that every newsideEffect
call in non-replay mode results in a new marker event recorded into the history. However,mutableSideEffect
only records a new marker if a value has changed. During the replay,mutableSideEffect
will not execute the function again, but it will return the exact same value as it was returning during the non-replay run.One good use case of
mutableSideEffect
is to access a dynamically changing config without breaking determinism. Even if called very frequently the config value is recorded only when it changes not causing any performance degradation due to a large history size.Caution: do not use
mutableSideEffect
function to modify any workflow state. Only use the mutableSideEffect's return value.- Parameters:
id
- id of the side effect call. It links multiple calls together. Calls with different ids are completely independent.func
- function that gets as input a result of a previousmutableSideEffect
call. The function executes its business logic (like checking config value) and if value didn't change returnsOptional.empty()
. If value has changed and needs to be recorded in the history then it is returned instead.callback
- function that accepts the result of the mutable side effect which is current or cached result of the func.
-
getVersion
void getVersion(java.lang.String changeId, int minSupported, int maxSupported, Functions.Proc2<java.lang.Integer,java.lang.RuntimeException> callback)
GetVersion is used to safely perform backwards incompatible changes to workflow definitions. It is not allowed to update workflow code while there are workflows running as it is going to break determinism. The solution is to have both old code that is used to replay existing workflows and the new one that is used when it is executed for the first time. GetVersion returns maxSupported version when executed for the first time. This version is recorded into the workflow history as a marker event. Even if maxSupported version is changed the version that was recorded is returned on replay. DefaultVersion constant contains version of code that wasn't versioned before.- Parameters:
changeId
- identifier of a particular changeminSupported
- min version supported for the changemaxSupported
- max version supported for the changecallback
- used to return version
-
newRandom
java.util.Random newRandom()
Replay safe random.
-
getMetricsScope
com.uber.m3.tally.Scope getMetricsScope()
- Returns:
- scope to be used for metrics reporting.
-
getEnableLoggingInReplay
boolean getEnableLoggingInReplay()
- Returns:
- whether we do logging during workflow code replay.
-
randomUUID
java.util.UUID randomUUID()
- Returns:
- replay safe UUID
-
upsertSearchAttributes
void upsertSearchAttributes(io.temporal.api.common.v1.SearchAttributes searchAttributes)
Updates or inserts search attributes used to index workflows.
-
getAttempt
int getAttempt()
- Returns:
- workflow retry attempt. default is 1
-
getCronSchedule
java.lang.String getCronSchedule()
- Returns:
- workflow cron schedule
-
-