Skip to main content

Crate temporalio_sdk

Crate temporalio_sdk 

Source
Expand description

This crate defines a Public Preview Temporal Rust SDK.

The SDK is built on top of Core and provides a native Rust experience for writing Temporal Workflows and Activities.

The SDK is in Public Preview and under active development. The API can and will continue to evolve.

An example of running an activity worker:

use std::str::FromStr;
use temporalio_client::{Client, ClientOptions, Connection, ConnectionOptions, Url};
use temporalio_common::worker::{
    WorkerDeploymentOptions, WorkerDeploymentVersion, WorkerTaskTypes,
};
use temporalio_macros::activities;
use temporalio_sdk::{
    Runtime, Worker, WorkerOptions,
    activities::{ActivityContext, ActivityError},
};

struct MyActivities;

#[activities]
impl MyActivities {
    #[activity]
    pub(crate) async fn echo(
        _ctx: ActivityContext,
        e: String,
    ) -> Result<String, ActivityError> {
        Ok(e)
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let connection_options =
        ConnectionOptions::new(Url::from_str("http://localhost:7233")?).build();
    let runtime = Runtime::new_assume_tokio(Default::default())?;
    let connection = Connection::connect(connection_options).await?;
    let client = Client::new(connection, ClientOptions::new("my_namespace").build())?;

    let worker_options = WorkerOptions::new("task_queue")
        .task_types(WorkerTaskTypes::activity_only())
        .deployment_options(WorkerDeploymentOptions {
            version: WorkerDeploymentVersion {
                deployment_name: "my_deployment".to_owned(),
                build_id: "my_build_id".to_owned(),
            },
            use_worker_versioning: false,
            default_versioning_behavior: None,
        })
        .register_activities(MyActivities)
        .build();

    let mut worker = Worker::new(&runtime, client, worker_options)?;
    worker.run().await?;

    Ok(())
}

Re-exports§

pub use crate::error::WorkflowRegistrationError;

Modules§

activities
Functionality related to defining and interacting with activities
error
Shared SDK error re-exports.
interceptors
User-definable interceptors are defined in this module
runtime
Runtime configuration and low-level Core worker building blocks.
worker_options_builder
Tools for manipulating the type state of WorkerOptionsBuilder.
workflow_interceptors
APIs for intercepting calls into workflow code and commands issued by workflow code.
workflows
Workflow authoring APIs and native workflow registration helpers.

Structs§

ActivityOptions
Options for scheduling an activity
ApplicationFailure
User-authored application failure metadata that can be converted into a Temporal failure.
BaseWorkflowContext
Non-generic base context containing all workflow execution infrastructure.
ChildWorkflowOptions
Options for scheduling a child workflow
ContinueAsNewOptions
Options for continuing a workflow as a new execution.
ExternalWorkflowHandle
Handle to an external workflow for sending signals or requesting cancellation.
LocalActivityOptions
Options for scheduling a local activity
MemoValue
A typed value used in a workflow memo update.
NexusOperationOptions
Options for Nexus Operations
Runtime
Holds shared state/components needed to back instances of workers and clients. More than one may be instantiated, but typically only one is needed. More than one runtime instance may be useful if multiple different telemetry settings are required.
Signal
Information needed to send a specific signal
SignalData
Data contained within a signal
StartChildWorkflowOutput
Output produced when an intercepted child workflow successfully starts.
StartedChildWorkflow
Child workflow in started state.
StartedNexusOperation
Handle to a started Nexus operation.
SyncWorkflowContext
Context provided to synchronous signal and update handlers.
TimerOptions
Options for timer
Worker
A worker that can poll for and respond to workflow tasks by using temporalio_macros::workflow, and activity tasks by using activities defined with temporalio_macros::activities.
WorkerOptions
Contains options for configuring a worker.
WorkerOptionsBuilder
Use builder syntax to set the inputs and finish with build().
WorkflowContext
Used within workflows to issue commands, get info, etc.
WorkflowContextView
Read-only view of workflow context for use in init and query handlers.

Enums§

ActExitValue
Activity functions may return these values when exiting
ActivityCancellationType
Controls when activity cancellation is reported back to a workflow.
ActivityCloseTimeouts
The timeouts applied to an activity’s completion.
ActivityExecutionError
Error type for activity execution outcomes.
ChildWorkflowCancellationType
Controls when child-workflow cancellation is reported to its parent.
ChildWorkflowExecutionError
Error returned when a child workflow execution fails.
ChildWorkflowStartError
Error returned when starting a child workflow fails.
ContinueAsNewVersioningBehavior
Versioning behavior to use for the first workflow task of a new continue-as-new run.
Namespace
Enum to help reference a namespace by either the namespace name or the namespace id
NexusOperationCancellationType
Controls when Nexus operation cancellation is reported to a workflow.
OutgoingActivityError
A typed outbound activity error.
OutgoingError
A typed outbound error surface used before encoding to a Temporal failure proto.
OutgoingWorkflowError
A typed outbound workflow failure.
ParentClosePolicy
Controls what happens to a child workflow when its parent closes.
RetryState
Describes why a retry did or did not occur.
StartChildWorkflowExecutionFailedCause
Possible causes of failure to start a child workflow
TimeoutType
Identifies which timeout expired.
TimerResult
Result of awaiting on a timer
VersioningIntent
Selects the worker versioning behavior intended for a command.
WorkflowIdReusePolicy
Controls whether a closed workflow ID may be reused.
WorkflowSignalError
Error returned when signaling a workflow fails.
WorkflowTermination
Represents ways a workflow can terminate without producing a normal result.

Traits§

CancellableFuture
A Future that can be cancelled. Used in the prototype SDK for cancelling operations like timers and activities.
CancellableFutureWithReason
A Future that can be cancelled with a reason
WorkflowRandomValue
A numeric value that can be generated by WorkflowContext::random.

Type Aliases§

PatchActivationCallback
Callback that decides whether a newly encountered patch should be activated.
WorkflowResult
The result of running a workflow.