pub struct AutomationEngine { /* private fields */ }Expand description
The automation runtime: stored triggers, the tick that fires them, and the run history they leave behind (#220).
Spawns through crate::fleet_provider::FleetProvider rather than a
concrete backend, so the same engine drives caliband over Unix sockets and
CalibanTask CRs under Kubernetes. It needs a shared [ConfigStore]:
the per-tick claim is what keeps replicas from double-firing, and a config
store local to one process could not arbitrate between them.
Implementations§
Source§impl AutomationEngine
impl AutomationEngine
Sourcepub fn new(config: Arc<dyn ConfigStore>, fleet: Arc<dyn FleetProvider>) -> Self
pub fn new(config: Arc<dyn ConfigStore>, fleet: Arc<dyn FleetProvider>) -> Self
Build an engine over a shared config store and a fleet backend.
Sourcepub async fn run(self: Arc<Self>, interval: Duration, shutdown: Receiver<bool>)
pub async fn run(self: Arc<Self>, interval: Duration, shutdown: Receiver<bool>)
Evaluate due automations every interval until shutdown flips.
A loop of its own rather than a step inside the fleet poll: how often schedules are checked and how often agents are reconciled are unrelated questions, and under k8s there is no fleet poll loop at all.
Sourcepub async fn list_automations(&self) -> Result<Vec<StoredAutomation>>
pub async fn list_automations(&self) -> Result<Vec<StoredAutomation>>
Every configured automation, ordered by id (#220).
Sourcepub async fn create_automation(
&self,
body: CreateAutomationBody,
) -> Result<CreatedAutomationResponse>
pub async fn create_automation( &self, body: CreateAutomationBody, ) -> Result<CreatedAutomationResponse>
Store a new automation, minting a signing key for a webhook trigger.
The key is returned once, here — nothing reads it back out afterwards, so an operator who loses it recreates the automation rather than recovering the secret.
Sourcepub async fn create_automation_at(
&self,
body: CreateAutomationBody,
created_at: DateTime<Utc>,
) -> Result<CreatedAutomationResponse>
pub async fn create_automation_at( &self, body: CreateAutomationBody, created_at: DateTime<Utc>, ) -> Result<CreatedAutomationResponse>
Self::create_automation with the creation time supplied.
created_at is the scheduling anchor, so injecting it is what lets a
caller — a test, or a future import/restore path — place an automation
on the timeline instead of always at “now”.
Sourcepub async fn delete_automation(&self, id: &str) -> Result<bool>
pub async fn delete_automation(&self, id: &str) -> Result<bool>
Remove an automation and its run history.
Sourcepub async fn set_automation_enabled(
&self,
id: &str,
enabled: bool,
) -> Result<()>
pub async fn set_automation_enabled( &self, id: &str, enabled: bool, ) -> Result<()>
Enable or disable an automation without discarding it.
Sourcepub async fn automation_runs(
&self,
id: &str,
limit: usize,
) -> Result<Vec<AutomationRun>>
pub async fn automation_runs( &self, id: &str, limit: usize, ) -> Result<Vec<AutomationRun>>
An automation’s recent runs, newest first.
Sourcepub async fn tick_automations(&self, now: DateTime<Utc>)
pub async fn tick_automations(&self, now: DateTime<Utc>)
Fire every cron automation whose tick has come due at now.
Safe to run on every replica concurrently: the store’s compare-and-set on the tick decides who acts, so this needs no lifecycle lease. That also means a scheduled spawn still happens when the lease holder is the replica that just died.
Sourcepub async fn fire_automation(
&self,
id: &str,
source: RunSource,
payload: Option<&Value>,
) -> Result<AutomationRun>
pub async fn fire_automation( &self, id: &str, source: RunSource, payload: Option<&Value>, ) -> Result<AutomationRun>
Fire one automation immediately, whatever its trigger.
Backs both “run now” and an accepted webhook. payload fills the task
template’s placeholders; None means the template must have none.
Records a run either way — including when the spawn fails, because an
automation that quietly stops working is the failure this history is
for.
Sourcepub async fn trigger_webhook(
&self,
id: &str,
body: &[u8],
signature: Option<&str>,
) -> Result<AutomationRun>
pub async fn trigger_webhook( &self, id: &str, body: &[u8], signature: Option<&str>, ) -> Result<AutomationRun>
Verify a webhook’s signature and, if it holds, fire the automation.
body is the raw request bytes: the signature covers exactly what
the sender transmitted, so re-serializing parsed JSON first would
compare a different byte string and reject every honest caller.
Auto Trait Implementations§
impl !RefUnwindSafe for AutomationEngine
impl !UnwindSafe for AutomationEngine
impl Freeze for AutomationEngine
impl Send for AutomationEngine
impl Sync for AutomationEngine
impl Unpin for AutomationEngine
impl UnsafeUnpin for AutomationEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more