Skip to main content

AutomationEngine

Struct AutomationEngine 

Source
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

Source

pub fn new(config: Arc<dyn ConfigStore>, fleet: Arc<dyn FleetProvider>) -> Self

Build an engine over a shared config store and a fleet backend.

Source

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.

Source

pub async fn list_automations(&self) -> Result<Vec<StoredAutomation>>

Every configured automation, ordered by id (#220).

Source

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.

Source

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”.

Source

pub async fn delete_automation(&self, id: &str) -> Result<bool>

Remove an automation and its run history.

Source

pub async fn set_automation_enabled( &self, id: &str, enabled: bool, ) -> Result<()>

Enable or disable an automation without discarding it.

Source

pub async fn automation_runs( &self, id: &str, limit: usize, ) -> Result<Vec<AutomationRun>>

An automation’s recent runs, newest first.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more