Skip to main content

wire/answer/
automation.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The schedule and the watch table as a page reads them
7//! (`crates/wire/spec/Answer/Automation.lean` ยง8-62).
8
9use kernel::Address;
10use serde::{Deserialize, Serialize};
11
12/// Both automation files, each in the order it was written, and the file
13/// that did not read with its reason. A file that is not there states no
14/// rows, which is a city that automates nothing.
15#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
16#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
17pub struct AutomationAnswer {
18    pub jobs: Vec<ScheduledJob>,
19    pub sources: Vec<WatchedSource>,
20    /// One line per file that did not read: its name and the refusal the
21    /// next tick would give. Its rows are absent rather than guessed.
22    pub unreadable: Vec<String>,
23}
24
25/// One row of `SCHEDULE.toml`.
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
27#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
28pub struct ScheduledJob {
29    pub name: String,
30    pub addr: Address,
31    pub task: String,
32    pub goal: String,
33    pub cadence: Cadence,
34}
35
36/// How often a scheduled job runs, in UTC minutes.
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
38#[serde(rename_all = "snake_case")]
39#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
40pub enum Cadence {
41    EveryMinutes {
42        minutes: u64,
43    },
44    /// The minute of the day.
45    DailyAt {
46        minute: u64,
47    },
48    /// The minute of the week, Monday first.
49    WeeklyAt {
50        minute: u64,
51    },
52}
53
54/// One row of `WATCH.toml`.
55#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
57pub struct WatchedSource {
58    pub name: String,
59    /// The substring that routes an arrival here.
60    pub matches: String,
61    pub addr: Address,
62    /// Whether an arrival from here may start work, or is only noticed.
63    pub starts_work: bool,
64}