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§
- 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
- Memo
Value - A typed value used in a workflow memo update.
- Nexus
Operation Options - 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
- Signal
Data - Data contained within a signal
- Start
Child Workflow Output - Output produced when an intercepted child workflow successfully starts.
- Started
Child Workflow - Child workflow in started state.
- Started
Nexus Operation - Handle to a started Nexus operation.
- 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
Cancellation Type - Controls when activity cancellation is reported back to a workflow.
- Activity
Close Timeouts - The timeouts applied to an activity’s completion.
- Activity
Execution Error - Error type for activity execution outcomes.
- Child
Workflow Cancellation Type - Controls when child-workflow cancellation is reported to its parent.
- 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
- Nexus
Operation Cancellation Type - Controls when Nexus operation cancellation is reported to a workflow.
- 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.
- Parent
Close Policy - Controls what happens to a child workflow when its parent closes.
- Retry
State - Describes why a retry did or did not occur.
- Start
Child Workflow Execution Failed Cause - Possible causes of failure to start a child workflow
- Timeout
Type - Identifies which timeout expired.
- Timer
Result - Result of awaiting on a timer
- Versioning
Intent - Selects the worker versioning behavior intended for a command.
- Workflow
IdReuse Policy - Controls whether a closed workflow ID may be reused.
- 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.
- Cancellable
Future With Reason - A Future that can be cancelled with a reason
- Workflow
Random Value - A numeric value that can be generated by
WorkflowContext::random.
Type Aliases§
- Patch
Activation Callback - Callback that decides whether a newly encountered patch should be activated.
- Workflow
Result - The result of running a workflow.