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§
- Activity
Options - Options for scheduling an activity
- Base
Workflow Context - Non-generic base context containing all workflow execution infrastructure.
- 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
- Parent
Workflow Info - Information about a parent workflow.
- Pending
Child Workflow - Child workflow in pending state
- 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
- 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
- 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
Execution Error - Error type for activity execution outcomes.
- Namespace
- Enum to help reference a namespace by either the namespace name or the namespace id
- Timer
Result - Result of awaiting on a timer
- 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§
- 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.