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 = "DrainRequested")]
44 DrainRequested,
45
46 #[sea_orm(string_value = "Signal")]
48 Signal,
49
50 #[sea_orm(string_value = "InternalError")]
52 InternalError,
53}
54
55#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
57#[sea_orm(table_name = "run")]
58pub struct Model {
59 #[sea_orm(primary_key)]
60 pub id: i32,
61 pub sandbox_id: i32,
62 pub pid: Option<i32>,
63 pub status: RunStatus,
64 pub exit_code: Option<i32>,
65 pub exit_signal: Option<i32>,
66 pub termination_reason: Option<TerminationReason>,
67 pub termination_detail: Option<String>,
68 pub signals_sent: Option<String>,
69 pub started_at: Option<DateTime>,
70 pub terminated_at: Option<DateTime>,
71}
72
73#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
79pub enum Relation {
80 #[sea_orm(
82 belongs_to = "super::sandbox::Entity",
83 from = "Column::SandboxId",
84 to = "super::sandbox::Column::Id",
85 on_delete = "Cascade"
86 )]
87 Sandbox,
88}
89
90impl Related<super::sandbox::Entity> for Entity {
91 fn to() -> RelationDef {
92 Relation::Sandbox.def()
93 }
94}
95
96impl std::fmt::Display for TerminationReason {
101 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
102 match self {
103 Self::Completed => f.write_str("Completed"),
104 Self::Failed => f.write_str("Failed"),
105 Self::MaxDurationExceeded => f.write_str("MaxDurationExceeded"),
106 Self::IdleTimeout => f.write_str("IdleTimeout"),
107 Self::DrainRequested => f.write_str("DrainRequested"),
108 Self::Signal => f.write_str("Signal"),
109 Self::InternalError => f.write_str("InternalError"),
110 }
111 }
112}
113
114impl ActiveModelBehavior for ActiveModel {}