durable

Attribute Macro durable 

Source
#[durable]
Expand description

Makes an async function durable by wrapping it with checkpoint-based caching and retry support.

The macro automatically:

  • Checks for existing checkpoint before execution
  • Returns cached result if checkpoint exists
  • Retries the function on failure (if max_retries > 0)
  • Records retry attempts to runtara-core for audit trail
  • Executes function and saves result as checkpoint on success

§Requirements

  • Function must be async
  • First parameter is the idempotency key (any type that implements Display)
  • Function must return Result<T, E> where T: Serialize + DeserializeOwned
  • SDK must be registered via RuntaraSdk::init() before calling

§Example - Basic (no retries)

use runtara_sdk::durable;

#[durable]
pub async fn fetch_order(key: &str, order_id: &str) -> Result<Order, OrderError> {
    // The key determines caching - same key = same cached result
    db.fetch_order(order_id).await
}

§Example - With retries

use runtara_sdk::durable;

#[durable(max_retries = 3, strategy = ExponentialBackoff, delay = 1000)]
pub async fn submit_order(key: &str, order: &Order) -> Result<OrderResult, OrderError> {
    // Retries up to 3 times with exponential backoff:
    // - First retry: 1000ms delay
    // - Second retry: 2000ms delay
    // - Third retry: 4000ms delay
    external_service.submit(order).await
}