2026-02-23 04:44:46 +00:00
|
|
|
use std::sync::{Arc, OnceLock};
|
|
|
|
|
|
|
|
|
|
use swactor::actor::{ActorAddress, Ctx};
|
|
|
|
|
use swactor::runtime::ExternalSender;
|
|
|
|
|
use swactor::Error;
|
|
|
|
|
|
|
|
|
|
use crate::actor::ProcessActor;
|
|
|
|
|
use crate::local::LocalDriver;
|
|
|
|
|
use crate::message::ProcessCommand;
|
|
|
|
|
use crate::session::ProcessSession;
|
refactor: remove dead code, consolidate files (#52)
Remove the unused TCP transport and dead CLI/simulation scaffolding and collapse scattered single-purpose modules into consolidated files across the dashboard, process, and simulation crates.
- crates/transport: drop the TCP transport (src/tcp.rs and its tcp feature), leaving only ed25519 identity and encoding utilities behind the iroh transport
- crates/dashboard: collapse actor_detail_html/actors_html/dashboard_html/topology_html into a single html.rs, drop command/parse.rs, and inline the trace types into lib.rs
- crates/process: fold driver, pipeline_types, queue, subscriber, waker, and local pipes/signal/wait into local/mod.rs, pipeline.rs, and a unified types.rs, consolidating the public re-exports
- crates/simulation: remove the ci subdirectory (local_sim, sim) and dead node/config/trace modules, and flatten the distribution subdirectory into top-level files
- crates/datastore: remove the unused store_cli, cli, and in-memory storage, and deduplicate crypto.rs across datastore and distribution (about 190 lines of shared code removed)
- crates/distribution: drop dead codec code and trim the messages module
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-25 14:33:04 +00:00
|
|
|
use crate::types::{EventQueue, ProcessDriver, ProcessSpec, ProcessWaker};
|
2026-02-23 04:44:46 +00:00
|
|
|
|
|
|
|
|
/// Spawn a process actor using the real `LocalDriver` (OS subprocess).
|
|
|
|
|
///
|
|
|
|
|
/// Creates a `ProcessActor<LocalDriver>`, spawns it in the runtime, and
|
|
|
|
|
/// wires up the waker so that I/O thread events automatically wake the actor.
|
|
|
|
|
///
|
|
|
|
|
/// Returns the actor's address. Send `ProcessCommand` messages to control it.
|
|
|
|
|
pub fn spawn_local_process(
|
|
|
|
|
ctx: &Ctx,
|
|
|
|
|
sender: &ExternalSender,
|
|
|
|
|
spec: ProcessSpec,
|
|
|
|
|
) -> Result<ActorAddress, Error> {
|
|
|
|
|
let waker_slot = Arc::new(OnceLock::new());
|
|
|
|
|
let queue = EventQueue::new();
|
|
|
|
|
let driver = LocalDriver::new(queue, waker_slot.clone());
|
|
|
|
|
spawn_process_inner(ctx, sender, spec, driver, waker_slot)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Spawn a process actor with a custom driver.
|
|
|
|
|
///
|
|
|
|
|
/// Useful for testing with `MockDriver` or other custom drivers while
|
|
|
|
|
/// still getting the full actor integration (waker, lifecycle, etc.).
|
|
|
|
|
pub fn spawn_process<D: ProcessDriver + 'static>(
|
|
|
|
|
ctx: &Ctx,
|
|
|
|
|
sender: &ExternalSender,
|
|
|
|
|
spec: ProcessSpec,
|
|
|
|
|
driver: D,
|
|
|
|
|
waker_slot: Arc<OnceLock<ProcessWaker>>,
|
|
|
|
|
) -> Result<ActorAddress, Error> {
|
|
|
|
|
spawn_process_inner(ctx, sender, spec, driver, waker_slot)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Spawn a process actor using the `SshDriver` (remote host via SSH).
|
|
|
|
|
///
|
|
|
|
|
/// Requires a tokio runtime handle (e.g. from `IrohDriver::tokio_handle()`)
|
|
|
|
|
/// and SSH connection config.
|
|
|
|
|
#[cfg(feature = "ssh")]
|
|
|
|
|
pub fn spawn_ssh_process(
|
|
|
|
|
ctx: &Ctx,
|
|
|
|
|
sender: &ExternalSender,
|
|
|
|
|
spec: ProcessSpec,
|
|
|
|
|
tokio_handle: tokio::runtime::Handle,
|
|
|
|
|
ssh_config: crate::ssh::SshConfig,
|
|
|
|
|
) -> Result<ActorAddress, Error> {
|
|
|
|
|
let waker_slot = Arc::new(OnceLock::new());
|
|
|
|
|
let queue = EventQueue::new();
|
|
|
|
|
let driver = crate::ssh::SshDriver::new(queue, waker_slot.clone(), tokio_handle, ssh_config);
|
|
|
|
|
spawn_process_inner(ctx, sender, spec, driver, waker_slot)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn spawn_process_inner<D: ProcessDriver + 'static>(
|
|
|
|
|
ctx: &Ctx,
|
|
|
|
|
sender: &ExternalSender,
|
|
|
|
|
spec: ProcessSpec,
|
|
|
|
|
driver: D,
|
|
|
|
|
waker_slot: Arc<OnceLock<ProcessWaker>>,
|
|
|
|
|
) -> Result<ActorAddress, Error> {
|
|
|
|
|
let (session, initial_actions) = ProcessSession::new(spec);
|
|
|
|
|
let actor = ProcessActor::new(session, driver, initial_actions, waker_slot.clone());
|
|
|
|
|
let addr = ctx.spawn(actor)?;
|
|
|
|
|
|
|
|
|
|
// Now that we have the address, fill the waker
|
|
|
|
|
let sender = sender.clone();
|
|
|
|
|
let waker = ProcessWaker::new(move || {
|
|
|
|
|
let _ = sender.send_to(addr, ProcessCommand::PollTick);
|
|
|
|
|
});
|
|
|
|
|
waker_slot
|
|
|
|
|
.set(waker.clone())
|
|
|
|
|
.expect("waker slot already set");
|
|
|
|
|
|
|
|
|
|
// Flush any events from the startup race window
|
|
|
|
|
waker.wake();
|
|
|
|
|
|
|
|
|
|
Ok(addr)
|
|
|
|
|
}
|