Activity options across SDKs
A workflow written in one language can call an activity that a worker in another language runs.
The PHP, Rust and Python SDKs name some activity options differently and take different units,
but each option sets the same field of the schedule_activity command. The Server applies that
field the same way whichever SDK sent it.
The same activity call in each SDK
Each call below runs payments.capture on the payments queue. It allows five attempts with
retry delays of 1, 2, 4 and 8 seconds, never retries a CardDeclined failure, and limits one
attempt to 30 seconds and the whole activity to 10 minutes.
$receipt = $context->activity('payments.capture', [$orderId], [
'queue' => 'payments',
'start_to_close_timeout' => 30,
'schedule_to_close_timeout' => '10 minutes',
'retry_policy' => [
'max_attempts' => 5,
'backoff_seconds' => [1, 2, 4, 8],
'non_retryable_error_types' => ['CardDeclined'],
],
]);
use std::time::Duration;
use durable_workflow::{ActivityOptions, ActivityRetryPolicy};
let receipt: String = ctx
.activity_typed_with_options(
"payments.capture",
ActivityOptions::new()
.task_queue("payments")
.start_to_close_timeout(Duration::from_secs(30))
.schedule_to_close_timeout(Duration::from_secs(10 * 60))
.retry_policy(
ActivityRetryPolicy::new(5)
.backoff_intervals([1, 2, 4, 8].map(Duration::from_secs))
.non_retryable_error_type("CardDeclined"),
),
order_id,
)
.await?;
from durable_workflow import ActivityRetryPolicy
receipt = yield ctx.schedule_activity(
"payments.capture",
[order_id],
queue="payments",
start_to_close_timeout=30,
schedule_to_close_timeout=600,
retry_policy=ActivityRetryPolicy(
max_attempts=5,
backoff_seconds=[1, 2, 4, 8],
non_retryable_error_types=["CardDeclined"],
),
)
Option mapping
PHP options are keys of the options array passed to $context->activity(). Rust options are
ActivityOptions and ActivityRetryPolicy methods, passed to ctx.activity_with_options or
ctx.activity_typed_with_options. Python options are keyword arguments of
ctx.schedule_activity(), with the retry fields on ActivityRetryPolicy. Every option sets
the schedule_activity field in the last column.
| Option | PHP | Rust | Python | Server field |
|---|---|---|---|---|
| Task queue | 'queue' => 'payments' | .task_queue("payments") | queue="payments" | queue |
| Attempts, including the first | 'retry_policy' => ['max_attempts' => 5] | ActivityRetryPolicy::new(5) | ActivityRetryPolicy(max_attempts=5) | retry_policy.max_attempts |
| Retry delays | 'backoff_seconds' => [1, 2, 4] in retry_policy, whole seconds | .backoff_intervals([..]) with Duration values, or .exponential_backoff(initial, coefficient, maximum) | backoff_seconds=[1, 2, 4], whole seconds, or ActivityRetryPolicy.exponential(..) | retry_policy.backoff_seconds |
| Failure types that are not retried | 'non_retryable_error_types' => [..] in retry_policy | .non_retryable_error_types([..]) or .non_retryable_error_type(..) | non_retryable_error_types=[..] | retry_policy.non_retryable_error_types |
| One attempt, from start to finish | 'start_to_close_timeout' => 30 | .start_to_close_timeout(Duration) | start_to_close_timeout=30 | start_to_close_timeout |
| Wait in the queue before an attempt starts | 'schedule_to_start_timeout' => 60 | .schedule_to_start_timeout(Duration) | schedule_to_start_timeout=60 | schedule_to_start_timeout |
| The whole activity, across all attempts | 'schedule_to_close_timeout' => 600 | .schedule_to_close_timeout(Duration) | schedule_to_close_timeout=600 | schedule_to_close_timeout |
| Longest gap between heartbeats | 'heartbeat_timeout' => 15 | .heartbeat_timeout(Duration) | heartbeat_timeout=15 | heartbeat_timeout |
The queue option is named queue in PHP and Python and task_queue in Rust. All three set the
same queue field.
Units
The Server records every timeout and retry delay in whole seconds.
- PHP timeouts take seconds as an integer or float, a string such as
'10 minutes', or aDateIntervalorCarbonInterval. Duration forms other than seconds need PHP SDK 3.9.0 or later. Each value is rounded up to whole seconds, and an activity timeout must be at least one second.backoff_secondslists whole seconds. - Rust timeouts and retry delays are
std::time::Durationvalues. Each one is rounded up to whole seconds, soDuration::from_millis(100)becomes one second. A timeout must be greater than zero. - Python timeouts are integer seconds and must be at least one second.
backoff_secondslists whole seconds.ActivityRetryPolicy.exponential(..)and theinitial_interval_secondsandmaximum_interval_secondsfields accept fractional seconds, and each generated delay is rounded up to whole seconds.
max_attempts counts every attempt, including the first. When there are more retries than
delays, the last delay repeats, so five attempts with backoff_seconds [1, 2] wait 1, 2, 2 and
2 seconds. The Server records the policy when it schedules the activity, and retries keep that
recorded policy even after the workflow code changes.
Related pages
- PHP SDK durations
- Rust SDK activity retry backoff
- Python SDK
- Worker protocol command types
- Laravel bridge handler registration, so that the PHP worker serves the activities other languages call