pub struct Heartbeat { /* private fields */ }Expand description
A periodic check-in for an always-on agent.
use std::time::Duration;
use autumn_plugin_agent::proactive::Heartbeat;
// Every 30 minutes during office hours, Oslo time, in the "ops" session.
let heartbeat = Heartbeat::cron("0 */30 8-18 * * Mon-Fri")
.timezone("Europe/Oslo")
.session("ops");Implementations§
Source§impl Heartbeat
impl Heartbeat
Sourcepub const TASK_NAME: &'static str = "agent_heartbeat"
pub const TASK_NAME: &'static str = "agent_heartbeat"
The scheduled-task name the heartbeat registers.
Sourcepub fn every(interval: Duration) -> Self
pub fn every(interval: Duration) -> Self
Tick after a fixed delay from the end of the previous tick.
Sourcepub fn cron(expression: impl Into<String>) -> Self
pub fn cron(expression: impl Into<String>) -> Self
Tick on a 6-field cron expression (sec min hour day month weekday).
Sourcepub fn timezone(self, timezone: impl Into<String>) -> Self
pub fn timezone(self, timezone: impl Into<String>) -> Self
The IANA time zone for a cron schedule. Ignored for fixed delays.
Sourcepub fn prompt(self, prompt: impl Into<String>) -> Self
pub fn prompt(self, prompt: impl Into<String>) -> Self
Replace the check-in prompt. Keep the HEARTBEAT_OK instruction
in it, or every tick will be delivered.
Sourcepub fn session(self, session: impl Into<SessionId>) -> Self
pub fn session(self, session: impl Into<SessionId>) -> Self
Run ticks inside this session, so the agent sees earlier ticks.
Sourcepub fn memory_scope(self, scope: MemoryScope) -> Self
pub fn memory_scope(self, scope: MemoryScope) -> Self
Bind memory to this scope instead of MemoryScope::agent.
Sourcepub const fn allow_actions(self) -> Self
pub const fn allow_actions(self) -> Self
Let ticks use every tool the app policy allows, not only read-only and internal ones.
Sourcepub const fn per_replica(self) -> Self
pub const fn per_replica(self) -> Self
Run on every replica instead of once per tick across the fleet.
Sourcepub fn precheck<F, Fut>(self, check: F) -> Self
pub fn precheck<F, Fut>(self, check: F) -> Self
Skip a tick, before any model call, when check answers false.
Sourcepub const fn schedule(&self) -> &HeartbeatSchedule
pub const fn schedule(&self) -> &HeartbeatSchedule
The configured schedule.
Sourcepub fn validate(&self) -> Result<(), AgentError>
pub fn validate(&self) -> Result<(), AgentError>
Check the schedule and prompt.
§Errors
Returns ErrorKind::Config for an interval under one second, a
blank cron expression, or a blank prompt.
Sourcepub async fn tick(
&self,
runtime: &AgentRuntime,
state: &AppState,
) -> Result<Option<AgentOutcome>, AgentError>
pub async fn tick( &self, runtime: &AgentRuntime, state: &AppState, ) -> Result<Option<AgentOutcome>, AgentError>
Run one tick. Returns None when the precheck skipped it.
§Errors
Returns AgentError when the run fails (see
Agent::run).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Heartbeat
impl !UnwindSafe for Heartbeat
impl Forget for Heartbeat
impl Freeze for Heartbeat
impl Send for Heartbeat
impl Sync for Heartbeat
impl Unpin for Heartbeat
impl UnsafeUnpin for Heartbeat
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.