56
loading...
This website collects cookies to deliver better user experience
Note: You can also set Workflow timeouts and retry policies you can set. This post deals only with Activity timeouts.
SimpleActivity
is first invoked inside a Workflow Worker on Task Queue sampleTaskQueue
. The precise method of invocation differs by SDK, and timeouts are also specified up front as part of Activity options:ao := workflow.ActivityOptions{
TaskQueue: "sampleTaskQueue",
ScheduleToCloseTimeout: time.Second * 500,
// ScheduleToStartTimeout: time.Second * 60, // usually not needed! see below
StartToCloseTimeout: time.Second * 60,
HeartbeatTimeout: time.Second * 10,
WaitForCancellation: false,
}
ctx = workflow.WithActivityOptions(ctx, ao)
var result string
err := workflow.ExecuteActivity(ctx, SimpleActivity, value).Get(ctx, &result)
if err != nil {
return err
}
ScheduleActivity
Command, which is sent to the Temporal Server. SimpleActivity
), activity task queue (sampleTaskQueue
), and activity ID. A RetryPolicy
was not specified, so Temporal uses the default Retry Policy.Bar
Activity Task Queue.The Activity Execution is now in a SCHEDULED
state.
Bar
Activity Task Queue picks up the Activity Task and begins execution.The Activity Execution is now in a STARTED
state.
CompleteActivityTask
message (together with the result of the Activity Execution) to Temporal Server, which now gives control back to the Workflow Worker to continue to the next line of code and repeat the process.The Activity Execution is now in a CLOSED
state.
STARTED
state) but the Worker crashes after that (so the Activity Execution never reaches CLOSED
state). ActivityTaskTimedOut
event internally which triggers the Server to attempt a retry based on the Activity Execution's RetryPolicy:
RetryPolicy
with MaximumAttempts > 1
.RetryPolicy
, the Schedule-To-Close Timeout is the best way to control retries based on the overall time that has elapsed.progress := 0
for hasWork {
// Send heartbeat message to the server.
activity.RecordHeartbeat(ctx, progress)
// Do some work.
...
progress++
}
temporal_activity_schedule_to_start_latency
metric and set alerts for that as a production scaling metric, rather than setting an explicit timeout for it.ScheduleToStart
is unique in that it doesn't result in a retry — all a retry would do is pop the activity right back on to the same queue!