Skip to main content

Crate temporalio_sdk

Crate temporalio_sdk 

Source
Expand description

This crate defines an alpha-stage Temporal Rust SDK.

Currently defining activities and running an activity-only worker is the most stable code. Workflow definitions exist and running a workflow worker works, but the API is still very unstable.

An example of running an activity worker:

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

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 telemetry_options = TelemetryOptions::builder().build();
    let runtime_options = RuntimeOptions::builder()
        .telemetry_options(telemetry_options)
        .build()?;
    let runtime = CoreRuntime::new_assume_tokio(runtime_options)?;

    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(())
}

Modules§

activities
Functionality related to defining and interacting with activities
interceptors
User-definable interceptors are defined in this module
worker_options_builder
Tools for manipulating the type state of WorkerOptionsBuilder.
workflows
Functionality related to defining and interacting with workflows

Structs§

ActivityOptions
Options for scheduling an activity
BaseWorkflowContext
Non-generic base context containing all workflow execution infrastructure.
CancelExternalOk
Successful result of sending a cancel request to an external workflow
ChildWorkflow
A stub representing an unstarted child workflow.
ChildWorkflowOptions
Options for scheduling a child workflow
LocalActivityOptions
Options for scheduling a local activity
NexusOperationOptions
Options for Nexus Operations
ParentWorkflowInfo
Information about a parent workflow.
PendingChildWorkflow
Child workflow in pending state
RootWorkflowInfo
Information about the root workflow in an execution chain.
Signal
Information needed to send a specific signal
SignalData
Data contained within a signal
SignalExternalOk
Successful result of sending a signal to an external workflow
SignalWorkflowOptions
Options for sending a signal to an external workflow
StartedChildWorkflow
Child workflow in started state
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
ActivityExecutionError
Error type for activity execution outcomes.
Namespace
Enum to help reference a namespace by either the namespace name or the namespace id
TimerResult
Result of awaiting on a timer
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.

Type Aliases§

CancelExternalWfResult
Result of awaiting on sending a cancel request to an external workflow
SignalExternalWfResult
Result of awaiting on sending a signal to an external workflow
WorkflowResult
The result of running a workflow.