microsandbox_db/entity/
run.rs1use sea_orm::entity::prelude::*;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
11#[sea_orm(rs_type = "String", db_type = "Text")]
12pub enum RunStatus {
13 #[sea_orm(string_value = "Running")]
15 Running,
16
17 #[sea_orm(string_value = "Terminated")]
19 Terminated,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
24#[sea_orm(rs_type = "String", db_type = "Text")]
25pub enum TerminationReason {
26 #[sea_orm(string_value = "Completed")]
28 Completed,
29
30 #[sea_orm(string_value = "Failed")]
32 Failed,
33
34 #[sea_orm(string_value = "MaxDurationExceeded")]
36 MaxDurationExceeded,
37
38 #[sea_orm(string_value = "IdleTimeout")]
40 IdleTimeout,
41
42 #[sea_orm(string_value = "AgentUnresponsive")]
44 AgentUnresponsive,
45
46 #[sea_orm(string_value = "ShutdownRequested")]
48 ShutdownRequested,
49
50 #[sea_orm(string_value = "DrainRequested")]
52 DrainRequested,
53
54 #[sea_orm(string_value = "Signal")]
56 Signal,
57
58 #[sea_orm(string_value = "InternalError")]
60 InternalError,
61}
62
63#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
65#[sea_orm(table_name = "run")]
66pub struct Model {
67 #[sea_orm(primary_key)]
68 pub id: i32,
69 pub sandbox_id: i32,
70 pub pid: Option<i32>,
71 pub status: RunStatus,
72 pub exit_code: Option<i32>,
73 pub exit_signal: Option<i32>,
74 pub termination_reason: Option<TerminationReason>,
75 pub termination_detail: Option<String>,
76 pub signals_sent: Option<String>,
77 pub started_at: Option<DateTime>,
78 pub terminated_at: Option<DateTime>,
79}
80
81#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
87pub enum Relation {
88 #[sea_orm(
90 belongs_to = "super::sandbox::Entity",
91 from = "Column::SandboxId",
92 to = "super::sandbox::Column::Id",
93 on_delete = "Cascade"
94 )]
95 Sandbox,
96}
97
98impl Related<super::sandbox::Entity> for Entity {
99 fn to() -> RelationDef {
100 Relation::Sandbox.def()
101 }
102}
103
104impl std::fmt::Display for TerminationReason {
109 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110 match self {
111 Self::Completed => f.write_str("Completed"),
112 Self::Failed => f.write_str("Failed"),
113 Self::MaxDurationExceeded => f.write_str("MaxDurationExceeded"),
114 Self::IdleTimeout => f.write_str("IdleTimeout"),
115 Self::AgentUnresponsive => f.write_str("AgentUnresponsive"),
116 Self::ShutdownRequested => f.write_str("ShutdownRequested"),
117 Self::DrainRequested => f.write_str("DrainRequested"),
118 Self::Signal => f.write_str("Signal"),
119 Self::InternalError => f.write_str("InternalError"),
120 }
121 }
122}
123
124impl ActiveModelBehavior for ActiveModel {}