Crate squads_temporal_sdk

Crate squads_temporal_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, 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.
ActivityFunction
Container for user-defined activity functions
ActivityOptions
Options for scheduling an activity
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
PendingChildWorkflow
Child workflow in pending state
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
TimerOptions
Options for timer
UpdateContext
Context for a workflow update
UpdateInfo
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
WorkflowFunction
The user’s async function / workflow code

Enums§

ActExitValue
Activity functions may return these values when exiting
ActivityError
Returned as errors from activity functions
Namespace
Enum to help reference a namespace by either the namespace name or the namespace id
TimerResult
Result of awaiting on a timer
WfExitValue
Workflow functions may return these values when exiting

Traits§

CancellableFuture
A Future that can be cancelled. Used in the prototype SDK for cancelling operations like timers and activities.
IntoActivityFunc
Closures / functions which can be turned into activity functions implement this trait
IntoUpdateHandlerFunc
Closures / functions which can be turned into update handler functions implement this trait
IntoUpdateValidatorFunc
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§

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