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, sync::Arc};
use temporal_sdk::{sdk_client_options, ActContext, Worker};
use squads_temporal_sdk_core::{init_worker, Url, CoreRuntime};
use squads_temporal_sdk_core_api::{
worker::{WorkerConfigBuilder, WorkerVersioningStrategy},
telemetry::TelemetryOptionsBuilder
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server_options = sdk_client_options(Url::from_str("http://localhost:7233")?).build()?;
let client = server_options.connect("default", None).await?;
let telemetry_options = TelemetryOptionsBuilder::default().build()?;
let runtime = CoreRuntime::new_assume_tokio(telemetry_options)?;
let worker_config = WorkerConfigBuilder::default()
.namespace("default")
.task_queue("task_queue")
.versioning_strategy(WorkerVersioningStrategy::None { build_id: "rust-sdk".to_owned() })
.build()?;
let core_worker = init_worker(&runtime, worker_config, client)?;
let mut worker = Worker::new_from_core(Arc::new(core_worker), "task_queue");
worker.register_activity(
"echo_activity",
|_ctx: ActContext, echo_me: String| async move { Ok(echo_me) },
);
worker.run().await?;
Ok(())
}Modules§
- interceptors
- User-definable interceptors are defined in this module
- prelude
- Prelude for easy importing of required types when defining workflow and activity definitions
- workflow
- Abstractions based on SDK crate for defining workflow and activity definitions in idiomatic Async Rust This is an experimental interface. Other convenience facilities and macros will be included if needed.
Structs§
- ActContext
- Used within activities to get info, heartbeat management etc.
- Activity
Function - Container for user-defined activity functions
- Activity
Options - Options for scheduling an activity
- Cancel
External Ok - Successful result of sending a cancel request to an external workflow
- Child
Workflow - A stub representing an unstarted child workflow.
- Child
Workflow Options - Options for scheduling a child workflow
- Local
Activity Options - Options for scheduling a local activity
- Nexus
Operation Options - Options for Nexus Operations
- Pending
Child Workflow - Child workflow in pending state
- Signal
- Information needed to send a specific signal
- Signal
Data - Data contained within a signal
- Signal
External Ok - Successful result of sending a signal to an external workflow
- Signal
Workflow Options - Options for sending a signal to an external workflow
- Started
Child Workflow - Child workflow in started state
- Timer
Options - Options for timer
- Update
Context - Context for a workflow update
- Update
Info - Extra information attached to workflow updates
- WfContext
- Used within workflows to issue commands, get info, etc.
- Worker
- A worker that can poll for and respond to workflow tasks by using WorkflowFunctions, and activity tasks by using ActivityFunctions
- Workflow
Function - The user’s async function / workflow code
Enums§
- ActExit
Value - Activity functions may return these values when exiting
- Activity
Error - Returned as errors from activity functions
- Namespace
- Enum to help reference a namespace by either the namespace name or the namespace id
- Timer
Result - Result of awaiting on a timer
- WfExit
Value - Workflow functions may return these values when exiting
Traits§
- Cancellable
Future - A Future that can be cancelled. Used in the prototype SDK for cancelling operations like timers and activities.
- Into
Activity Func - Closures / functions which can be turned into activity functions implement this trait
- Into
Update Handler Func - Closures / functions which can be turned into update handler functions implement this trait
- Into
Update Validator Func - Closures / functions which can be turned into update validation functions implement this trait
Functions§
- sdk_
client_ options - Returns a ClientOptionsBuilder with required fields set to appropriate values for the Rust SDK.
Type Aliases§
- Cancel
External WfResult - Result of awaiting on sending a cancel request to an external workflow
- Signal
External WfResult - Result of awaiting on sending a signal to an external workflow
- Workflow
Result - The result of running a workflow