Skip to main content

aion_worker/
lib.rs

1//! Rust remote-worker SDK for executing Aion activities over gRPC.
2//!
3//! The SDK registers typed activity handlers, receives pushed tasks from an
4//! `aion-server`, executes them out-of-process, reports results, and sends
5//! heartbeats for long-running work.
6//!
7//! # Example
8//!
9//! ```no_run
10//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
11//! use aion_worker::{ActivityContext, HandlerFuture, Worker, WorkerConfig};
12//! use serde::{Deserialize, Serialize};
13//!
14//! #[derive(Deserialize, Serialize)]
15//! struct Input { name: String }
16//!
17//! #[derive(Serialize)]
18//! struct Output { message: String }
19//!
20//! fn greet(input: Input, _context: &ActivityContext) -> HandlerFuture<'_, Output> {
21//!     Box::pin(async move { Ok(Output { message: format!("hello, {}", input.name) }) })
22//! }
23//!
24//! let config = WorkerConfig::builder()
25//!     .endpoint("http://127.0.0.1:50051")
26//!     .task_queue("default")
27//!     .identity("rust-worker-1")
28//!     .max_concurrency(4)
29//!     .reconnect_initial_backoff(std::time::Duration::from_millis(500))
30//!     .reconnect_max_backoff(std::time::Duration::from_secs(5))
31//!     .reconnect_max_attempts(10)
32//!     .build()?;
33//!
34//! Worker::builder(config)
35//!     .register_activity("examples.greet", greet)?
36//!     .build()?
37//!     .run()
38//!     .await?;
39//! # Ok(())
40//! # }
41//! ```
42
43/// Typed activity registration and failure classification.
44pub mod activity;
45/// Worker endpoint, identity, transport, and reconnect configuration.
46pub mod config;
47/// Per-activity execution context, heartbeat, and cancellation handles.
48pub mod context;
49/// Worker runtime and configuration errors.
50pub mod error;
51/// Worker-session protocol abstractions and task types.
52pub mod protocol;
53/// Activity dispatch and task-serving loops.
54pub mod runtime;
55/// High-level worker builder and run loop.
56pub mod worker;
57
58pub use activity::{
59    ActivityFailure, ActivityRegistry, Classification, DuplicateActivityType, HandlerFuture,
60};
61pub use config::{
62    ReconnectConfig, TransportCredentials, WorkerConfig, WorkerConfigBuildError,
63    WorkerConfigBuilder,
64};
65pub use context::{ActivityCancellationHandle, ActivityContext, HeartbeatRequest};
66pub use error::{MissingActivityHandler, WorkerError};
67pub use protocol::{
68    ActivityTask, GrpcWorkerSession, PendingActivityReport, ReconnectBackoff,
69    RegisteredSessionInfo, UnackedResultTracker, WorkerSession, WorkerSessionEvent,
70    WorkerTaskStream, connect_registered_grpc_session, re_report_unacked, reconnect_with_backoff,
71    reconnect_with_sleep, register_connected_session, validate_activity_handlers,
72};
73pub use runtime::{
74    ActivityDispatcher, DispatchOutcome, NoShutdown, ServeEnd, SessionHealth,
75    TypedActivityDispatcher, decode_payload, encode_payload, serve_activity_tasks,
76    serve_activity_tasks_until,
77};
78pub use worker::{EmptyActivitySet, Worker, WorkerBuilder, run_worker_with_session};