supercode_interchange/orchestration/
job.rs1use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::ontology::Residue;
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
10#[serde(tag = "kind", rename_all = "snake_case")]
11pub enum Schedule {
12 Once {
14 run_at: String,
16 },
17 Interval {
19 minutes: f64,
21 },
22 Cron {
24 expr: String,
26 #[serde(default, skip_serializing_if = "Option::is_none")]
29 tz: Option<String>,
30 },
31}
32
33impl Eq for Schedule {}
34
35impl Schedule {
36 pub fn kind(&self) -> &'static str {
38 match self {
39 Self::Once { .. } => "once",
40 Self::Interval { .. } => "interval",
41 Self::Cron { .. } => "cron",
42 }
43 }
44}
45
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
48#[serde(tag = "kind", rename_all = "snake_case")]
49pub enum Target {
50 Origin,
52 Home,
54 Local,
56 Explicit {
58 platform: String,
60 #[serde(default, skip_serializing_if = "Option::is_none")]
62 chat_id: Option<String>,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
65 thread_id: Option<String>,
66 },
67}
68
69impl Target {
70 pub fn render(&self) -> String {
72 match self {
73 Self::Origin => "origin".into(),
74 Self::Home => "home".into(),
75 Self::Local => "local".into(),
76 Self::Explicit {
77 platform,
78 chat_id,
79 thread_id,
80 } => {
81 let mut s = platform.clone();
82 if let Some(c) = chat_id {
83 s.push(':');
84 s.push_str(c);
85 if let Some(t) = thread_id {
86 s.push(':');
87 s.push_str(t);
88 }
89 }
90 s
91 }
92 }
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
98pub struct Repeat {
99 #[serde(default)]
101 pub times: Option<u32>,
102 #[serde(default)]
104 pub completed: u32,
105}
106
107#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
109pub struct JobOrigin {
110 pub platform: String,
112 #[serde(default)]
114 pub chat_type: Option<String>,
115 #[serde(default)]
117 pub chat_id: Option<String>,
118 #[serde(default)]
120 pub thread_id: Option<String>,
121}
122
123#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
125pub struct Job {
126 pub id: String,
128 pub schedule: Schedule,
130 #[serde(default)]
132 pub prompt: Option<String>,
133 #[serde(default)]
135 pub workdir: Option<String>,
136 #[serde(default)]
138 pub model: Option<String>,
139 #[serde(default)]
141 pub skills: Vec<String>,
142 #[serde(default)]
144 pub context_from: Option<Vec<String>>,
145 pub deliver: Target,
147 #[serde(default)]
149 pub failure_deliver: Option<Target>,
150 #[serde(default)]
152 pub origin: Option<JobOrigin>,
153 #[serde(default)]
155 pub attach_to_session: Option<bool>,
156 #[serde(default)]
158 pub repeat: Option<Repeat>,
159 #[serde(default = "default_true")]
161 pub enabled: bool,
162 #[serde(default)]
164 pub next_run_at: Option<String>,
165 #[serde(default)]
167 pub last_run_at: Option<String>,
168 #[serde(default)]
170 pub last_status: Option<String>,
171 #[serde(default)]
173 pub created_at: Option<String>,
174 #[serde(default)]
176 pub residue: Residue,
177}
178
179fn default_true() -> bool {
180 true
181}