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.
44/// What this build actually covered, announced through test names (#119).
45#[cfg(test)]
46mod build_coverage;
47
48pub mod activity;
49/// A contained command's output, streamed into the activity transcript.
50pub mod command_transcript;
51/// Worker endpoint, identity, transport, and reconnect configuration.
52pub mod config;
53/// Per-activity execution context, heartbeat, and cancellation handles.
54pub mod context;
55/// Worker runtime and configuration errors.
56pub mod error;
57/// Process-group containment: the one core, and the cancellable command built
58/// on it.
59pub mod process;
60/// Worker-session protocol abstractions and task types.
61pub mod protocol;
62/// Activity dispatch and task-serving loops.
63pub mod runtime;
64/// Declared commands as activities — an action that runs without a Rust crate.
65pub mod shell;
66/// High-level worker builder and run loop.
67pub mod worker;
68
69pub use activity::{
70 ActivityFailure, ActivityRegistry, Classification, DescriptorNameMismatch,
71 DuplicateActivityType, HandlerFuture, activity_descriptor,
72};
73pub use command_transcript::CommandTranscript;
74pub use config::{
75 ReconnectConfig, TransportCredentials, WorkerConfig, WorkerConfigBuildError,
76 WorkerConfigBuilder,
77};
78pub use context::{ActivityCancellationHandle, ActivityContext, HeartbeatRequest};
79pub use error::{MissingActivityHandler, WorkerError};
80pub use process::{
81 CancellableCommandOutput, CommandOutputObserver, CommandStream, ContainedChild,
82 PROCESS_GROUP_TERMINATION_GRACE, ProcessGroupError, run_cancellable_command,
83};
84pub use protocol::{
85 ActivityTask, GrpcWorkerSession, PendingActivityReport, ReconnectBackoff,
86 RegisteredSessionInfo, UnackedResultTracker, WorkerSession, WorkerSessionEvent,
87 WorkerTaskStream, connect_registered_grpc_session, re_report_unacked, reconnect_with_backoff,
88 reconnect_with_sleep, register_connected_session, validate_activity_handlers,
89};
90#[cfg(feature = "liminal-transport")]
91pub use runtime::liminal::{
92 AgentHarnessConfig, DispatchRequest, DispatchResponse, InterventionReply, InterventionRequest,
93 LiminalActivityWorker,
94};
95pub use runtime::{
96 ActivityDispatcher, ActivityEventSender, ControlMessage, ControlReceiver, ControlRegistry,
97 DispatchOutcome, NoShutdown, ServeEnd, SessionGuard, SessionHealth, SessionKey,
98 TypedActivityDispatcher, decode_payload, encode_payload, harness_error_to_outcome,
99 serve_activity_tasks, serve_activity_tasks_until, spawn_agent, spawn_dyn_agent,
100};
101#[cfg(feature = "liminal-transport")]
102pub use runtime::{RedialTiming, serve_with_redial};
103pub use schemars;
104pub use shell::spawn_failure_permits_retry;
105pub use worker::{EmptyActivitySet, Worker, WorkerBuilder, run_worker_with_session};