feat: add scheduler data types (Schedule, ScheduledJob, JobRun)

This commit is contained in:
xiaoski 2026-05-05 00:08:00 +08:00
parent 75b8f7b8a5
commit 4e5f412c2d
5 changed files with 58 additions and 0 deletions

View File

@ -9,6 +9,7 @@ pub mod protocol;
pub mod channels; pub mod channels;
pub mod logging; pub mod logging;
pub mod observability; pub mod observability;
pub mod scheduler;
pub mod skills; pub mod skills;
pub mod storage; pub mod storage;
pub mod tools; pub mod tools;

5
src/scheduler/mod.rs Normal file
View File

@ -0,0 +1,5 @@
pub mod types;
pub mod store;
pub mod tools;
pub use types::{JobRun, Schedule, ScheduledJob};

1
src/scheduler/store.rs Normal file
View File

@ -0,0 +1 @@
// Stub — will be filled in Task 5

1
src/scheduler/tools.rs Normal file
View File

@ -0,0 +1 @@
// Stub — will be filled in Task 9

50
src/scheduler/types.rs Normal file
View File

@ -0,0 +1,50 @@
use serde::{Deserialize, Serialize};
/// How a job is scheduled. Serialized as JSON in the database `schedule` column.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Schedule {
/// One-shot: fires once at a specific Unix millisecond timestamp, then disables.
#[serde(rename = "at")]
At { at: i64 },
/// Recurring: fires every `every_ms` milliseconds.
#[serde(rename = "every")]
Every { every_ms: u64 },
/// Recurring: fires on a cron schedule with optional timezone.
#[serde(rename = "cron")]
Cron { expr: String, tz: Option<String> },
}
/// A scheduled job stored in the database.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScheduledJob {
pub id: String,
pub name: String,
/// JSON-serialized `Schedule` stored as TEXT in SQLite.
pub schedule: Schedule,
pub prompt: String,
pub channel: String,
pub chat_id: String,
pub model: Option<String>,
pub enabled: bool,
pub delete_after_run: bool,
pub next_run_at: i64,
pub last_run_at: Option<i64>,
pub last_status: Option<String>,
pub last_error: Option<String>,
pub created_at: i64,
pub updated_at: i64,
}
/// A single execution record for a job.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JobRun {
pub id: i64,
pub job_id: String,
pub started_at: i64,
pub finished_at: i64,
pub status: String,
pub output: Option<String>,
pub error: Option<String>,
pub duration_ms: i64,
}