mirror of
https://github.com/ruvnet/RuView
synced 2026-07-28 18:21:42 +00:00
3292bd2c5d
ADR-161 implemented RunMode::Single (AtomicBool re-entrancy guard) + Parallel but honestly left Restart/Queued/max as "ACCEPTED-FUTURE / unbounded parallel" — every non-Single mode spawned an unbounded task. This makes them real. New `runmode` module — per-automation RunState owns the machinery: - Restart: aborts the in-flight action task (tokio::task::AbortHandle) and starts a fresh one. - Queued: serializes runs in arrival order via a per-automation async Mutex — sequential, never concurrent, nothing dropped. - max: N: caps concurrency at N via a per-automation Semaphore; triggers beyond N queue (await a permit) rather than running concurrently (HA bounded semantics). Documented in the module table. - Single/IgnoreFirst/Parallel preserved. engine.rs now holds a RunState per registration and calls run_state.dispatch() at all three trigger sites (event loop, timer, fire_time_for_test); the old spawn_run is removed. engine.rs trimmed to 433 lines. Tests (tests/engine_behaviors.rs) — verified to FAIL on the old unbounded- parallel dispatch (simulated and confirmed each panics), pass on the new: - restart_mode_cancels_prior_run (old: both runs complete → 2; new: 1) - queued_mode_runs_sequentially_not_concurrently (old: max concurrency 3; new: all 3 run, max concurrency 1) - max_two_caps_concurrency_at_two (old: 4 concurrent; new: all 4 run, max 2) homecore-automation --no-default-features: 45 passed (lib 37, engine_behaviors 8), 0 failed. Co-Authored-By: claude-flow <ruv@ruv.net>
32 lines
1.2 KiB
Rust
32 lines
1.2 KiB
Rust
//! homecore-automation — ADR-129 HOMECORE-AUTO
|
|
//!
|
|
//! Automation engine, trigger evaluator, MiniJinja template evaluator, and
|
|
//! script action executor for the HOMECORE Home Assistant port.
|
|
//!
|
|
//! ## Layout
|
|
//!
|
|
//! - [`automation`] — `Automation` struct: id, alias, mode, triggers, conditions, actions
|
|
//! - [`trigger`] — `Trigger` enum + `EvaluateTrigger` trait
|
|
//! - [`condition`] — `Condition` enum + async `evaluate` method + `EvalContext`
|
|
//! - [`action`] — `Action` enum + async `execute` method + `ExecutionContext`
|
|
//! - [`template`] — MiniJinja environment with HA-compat globals (states, state_attr, is_state, now)
|
|
//! - [`engine`] — `AutomationEngine`: subscribes to event bus, drives trigger→condition→action pipeline
|
|
//! - [`error`] — crate-wide `AutomationError`
|
|
|
|
pub mod automation;
|
|
pub mod trigger;
|
|
pub mod condition;
|
|
pub mod action;
|
|
pub mod template;
|
|
pub mod engine;
|
|
pub mod runmode;
|
|
pub mod error;
|
|
|
|
pub use automation::{Automation, RunMode};
|
|
pub use trigger::{EvaluateTrigger, Trigger, TriggerContext};
|
|
pub use condition::{Condition, EvalContext};
|
|
pub use action::{Action, ExecutionContext};
|
|
pub use template::TemplateEnvironment;
|
|
pub use engine::AutomationEngine;
|
|
pub use error::AutomationError;
|