Skip to main content

Module retry

Module retry 

Source
Expand description

Semantic retry policies for host-managed operations and local user code.

Named policies are installed and resolved by the Golem host. A resolved policy can also be compiled into a RetrySchedule to retry arbitrary user code in the component:

use golem_rust::retry::{
    PredicateValue, Props, RetrySchedule, resolve_retry_policy,
};
use std::io;

let context = vec![(
    Props::STATUS_CODE.to_string(),
    PredicateValue::Integer(503),
)];
let raw = resolve_retry_policy("send", "email://welcome", &context)
    .map_err(io::Error::other)?
    .ok_or_else(|| io::Error::other("no matching retry policy"))?;
let schedule = RetrySchedule::try_from(&raw)?;

schedule
    .retry_with_properties(
        async || Err::<(), _>(io::Error::other("temporarily unavailable")),
        |_| context.clone(),
    )
    .await?;

Resolution remains host-driven, but RetrySchedule execution is a local guest loop. Local attempts do not become executor RetryAttempt entries or one host-managed retry sequence.

Re-exports§

pub use builder::NamedPolicy;
pub use builder::Policy;
pub use builder::Predicate;
pub use builder::Props;
pub use builder::RetryBuilderError;
pub use builder::Value;

Modules§

builder

Structs§

CountBoxConfig
NamedRetryPolicy
── Named policy rule ──────────────────────────────────────────── A named retry policy rule: predicate selects when it applies, policy defines the retry strategy, priority controls evaluation order (higher = checked first).
RetryPolicy
A composable retry policy tree. Root is nodes[0]. Children referenced by policy-node-index.
RetryPolicyGuard
Guard that restores the previous state of a named retry policy on drop. If the policy existed before, it is restored; if it was newly added, it is removed.
RetryPredicate
A composable predicate tree for matching retry contexts. Root is nodes[0]. Children referenced by predicate-node-index.
RetrySchedule
A validated retry schedule for retrying fallible user code locally.

Enums§

PolicyNode
PredicateNode
PredicateValue
── Predicate value ────────────────────────────────────────────── Dynamic value for property comparisons in retry predicates
RetryPolicyError
An error found while validating a flattened raw retry policy.

Functions§

get_retry_policies
Get all retry policies active for this agent.
get_retry_policy_by_name
Get a specific retry policy by name.
remove_retry_policy
Remove a named retry policy by name (persisted to oplog).
resolve_retry_policy
Resolve the matching retry policy for a given operation context. Evaluates named policies in descending priority order; returns the policy from the first rule whose predicate matches, or none. Invalid predicates return an error without trapping the invocation.
set_named_policy
Add or overwrite a high-level named retry policy after validating and flattening it into the raw WIT representation.
set_retry_policy
Add or overwrite a named retry policy (persisted to oplog). If a policy with the same name exists, it is replaced.
use_named_policy
Temporarily sets a high-level named retry policy after validating and flattening it into the raw WIT representation.
use_retry_policy
Temporarily sets a named retry policy. When the returned guard is dropped, the previous policy with the same name is restored (or removed if it didn’t exist).
with_named_policy
Executes the given function with a high-level named retry policy temporarily set.
with_named_policy_async
Executes the given async function with a high-level named retry policy temporarily set.
with_retry_policy
Executes the given function with a named retry policy temporarily set.
with_retry_policy_async
Executes the given async function with a named retry policy temporarily set.