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};
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(())
}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
- worker_
options_ builder - Tools for manipulating the type state of
WorkerOptionsBuilder. - workflows
- Workflow authoring APIs and native workflow registration helpers.
Structs§
- Activity
Options - Options for scheduling an activity
- Application
Failure - User-authored application failure metadata that can be converted into a Temporal failure.
- Base
Workflow Context - Non-generic base context containing all workflow execution infrastructure.
- Child
Workflow Options - Options for scheduling a child workflow
- Continue
AsNew Options - Options for continuing a workflow as a new execution.
- External
Workflow Handle - Handle to an external workflow for sending signals or requesting cancellation.
- Local
Activity Options - Options for scheduling a local activity
- Nexus
Operation Options - Options for Nexus Operations
- Parent
Workflow Info - Information about a parent workflow.
- Root
Workflow Info - Information about the root workflow in an execution chain.
- Signal
- Information needed to send a specific signal
- Signal
Data - Data contained within a signal
- Started
Child Workflow - Child workflow in started state.
- Sync
Workflow Context - Context provided to synchronous signal and update handlers.
- Timer
Options - 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.
- Worker
Options - Contains options for configuring a worker.
- Worker
Options Builder - Use builder syntax to set the inputs and finish with
build(). - Workflow
Context - Used within workflows to issue commands, get info, etc.
- Workflow
Context View - Read-only view of workflow context for use in init and query handlers.
Enums§
- ActExit
Value - Activity functions may return these values when exiting
- Activity
Close Timeouts - The timeouts applied to an activity’s completion.
- Activity
Execution Error - Error type for activity execution outcomes.
- Child
Workflow Execution Error - Error returned when a child workflow execution fails.
- Child
Workflow Start Error - Error returned when starting a child workflow fails.
- Continue
AsNew Versioning Behavior - 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
- Outgoing
Activity Error - A typed outbound activity error.
- Outgoing
Error - A typed outbound error surface used before encoding to a Temporal failure proto.
- Outgoing
Workflow Error - A typed outbound workflow failure.
- Start
Child Workflow Execution Failed Cause - Possible causes of failure to start a child workflow
- Timer
Result - Result of awaiting on a timer
- Workflow
Signal Error - Error returned when signaling a workflow fails.
- Workflow
Termination - Represents ways a workflow can terminate without producing a normal result.
Traits§
- Cancellable
Future - A Future that can be cancelled. Used in the prototype SDK for cancelling operations like timers and activities.
Type Aliases§
- Workflow
Result - The result of running a workflow.