Activity Timeouts
Activity timeouts
Each Activity Timeout controls a different aspect of how long an Activity Execution can take:
At least one of start_to_close_timeout or schedule_to_close_timeout is required.
The Temporal Service fills in whichever timeouts you leave unset and caps the rest against each other, so the values it stores can differ from the ones you passed. See How the Temporal Service resolves Activity timeouts.
ruby-sandbox/activities/timeouts/workflows.rb
Temporalio::Workflow.execute_activity(
MyActivity,
{ greeting: 'Hello', name: },
start_to_close_timeout: 5 * 60
)
Activity Retry Policy
By default, Activities use a system Retry Policy. You can override it by specifying a custom Retry Policy.
To create an Activity Retry Policy in Ruby, set the retry_policy parameter when executing an activity.
ruby-sandbox/activities/timeouts/workflows.rb
Temporalio::Workflow.execute_activity(
MyActivity,
{ greeting: 'Hello', name: },
start_to_close_timeout: 5 * 60,
retry_policy: Temporalio::RetryPolicy.new(max_interval: 10)
)
Override the retry interval with next_retry_delay
If you raise an application-level error, you can override the Retry Policy's delay by specifying a new delay.
ruby-sandbox/activities/timeouts/next_retry_delay_activity.rb
raise Temporalio::Error::ApplicationError.new(
'Some error',
type: 'SomeErrorType',
next_retry_delay: 3 * Temporalio::Activity::Context.current.info.attempt
)
Heartbeat an Activity
A Heartbeat is a periodic signal from the Worker to the Temporal Service indicating the Activity is still alive and making progress.
- Heartbeats are used to detect Worker failure.
- Cancellations are delivered via Heartbeats.
- Heartbeats may contain custom progress details.
ruby-sandbox/activities/timeouts/heartbeat_activity.rb
class MyActivity < Temporalio::Activity::Definition
def execute
# This is a naive loop simulating work, but similar heartbeat logic
# applies to other scenarios as well
loop do
# Send heartbeat
Temporalio::Activity::Context.current.heartbeat
# Sleep before heartbeating again
sleep(3)
end
end
end
Heartbeat Timeout
The Heartbeat Timeout sets the maximum duration between Heartbeats before the Temporal Service considers the Activity failed.
ruby-sandbox/activities/timeouts/workflows.rb
Temporalio::Workflow.execute_activity(
MyActivity,
{ greeting: 'Hello', name: },
start_to_close_timeout: 5 * 60,
heartbeat_timeout: 5
)