1use std::time::Duration;
4
5use super::resources::ByteSize;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum QosLevel {
10 BestEffort,
12 Background,
14 Interactive,
16 Realtime,
18}
19
20#[derive(Debug, Clone, PartialEq)]
22pub struct RetryPolicy {
23 pub max_retries: usize,
25 pub initial_backoff: Duration,
27 pub backoff_multiplier: f64,
29}
30
31impl Default for RetryPolicy {
32 fn default() -> Self {
33 Self {
34 max_retries: 3,
35 initial_backoff: Duration::from_millis(100),
36 backoff_multiplier: 2.0,
37 }
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Default)]
43pub struct ResourceLimits {
44 pub max_memory: Option<ByteSize>,
46 pub max_cores: Option<usize>,
48 pub max_gpu_memory: Option<ByteSize>,
50}
51
52#[derive(Debug, Clone, PartialEq, Default)]
54pub struct ObservabilityConfig {
55 pub tracing: bool,
57 pub metrics: bool,
59 pub sampling_rate: f64,
61}
62
63#[derive(Debug, Clone, PartialEq)]
65pub struct ExecutionPolicy {
66 pub qos: QosLevel,
68 pub preemptible: bool,
70 pub timeout: Option<Duration>,
72 pub retry: RetryPolicy,
74 pub limits: ResourceLimits,
76 pub observability: ObservabilityConfig,
78}
79
80impl Default for ExecutionPolicy {
81 fn default() -> Self {
82 Self {
83 qos: QosLevel::Interactive,
84 preemptible: true,
85 timeout: None,
86 retry: RetryPolicy::default(),
87 limits: ResourceLimits::default(),
88 observability: ObservabilityConfig::default(),
89 }
90 }
91}
92
93impl ExecutionPolicy {
94 pub fn realtime() -> Self {
96 Self {
97 qos: QosLevel::Realtime,
98 preemptible: false,
99 timeout: Some(Duration::from_millis(100)),
100 ..Default::default()
101 }
102 }
103
104 pub fn batch() -> Self {
106 Self {
107 qos: QosLevel::BestEffort,
108 preemptible: true,
109 timeout: None,
110 ..Default::default()
111 }
112 }
113
114 pub fn interactive() -> Self {
116 Self::default()
117 }
118
119 pub fn debug() -> Self {
121 Self {
122 qos: QosLevel::BestEffort,
123 preemptible: true,
124 timeout: None,
125 observability: ObservabilityConfig {
126 tracing: true,
127 metrics: true,
128 sampling_rate: 1.0,
129 },
130 ..Default::default()
131 }
132 }
133}