Skip to main content

Activity Timeouts - Ruby SDK

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.

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.

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.

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.
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.

Temporalio::Workflow.execute_activity(
MyActivity,
{ greeting: 'Hello', name: },
start_to_close_timeout: 5 * 60,
heartbeat_timeout: 5
)