use sea_orm::entity::prelude::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Text")]
pub enum RunStatus {
#[sea_orm(string_value = "Running")]
Running,
#[sea_orm(string_value = "Terminated")]
Terminated,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Text")]
pub enum TerminationReason {
#[sea_orm(string_value = "Completed")]
Completed,
#[sea_orm(string_value = "Failed")]
Failed,
#[sea_orm(string_value = "MaxDurationExceeded")]
MaxDurationExceeded,
#[sea_orm(string_value = "IdleTimeout")]
IdleTimeout,
#[sea_orm(string_value = "DrainRequested")]
DrainRequested,
#[sea_orm(string_value = "Signal")]
Signal,
#[sea_orm(string_value = "InternalError")]
InternalError,
}
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "run")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub sandbox_id: i32,
pub pid: Option<i32>,
pub status: RunStatus,
pub exit_code: Option<i32>,
pub exit_signal: Option<i32>,
pub termination_reason: Option<TerminationReason>,
pub termination_detail: Option<String>,
pub signals_sent: Option<String>,
pub started_at: Option<DateTime>,
pub terminated_at: Option<DateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::sandbox::Entity",
from = "Column::SandboxId",
to = "super::sandbox::Column::Id",
on_delete = "Cascade"
)]
Sandbox,
}
impl Related<super::sandbox::Entity> for Entity {
fn to() -> RelationDef {
Relation::Sandbox.def()
}
}
impl std::fmt::Display for TerminationReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Completed => f.write_str("Completed"),
Self::Failed => f.write_str("Failed"),
Self::MaxDurationExceeded => f.write_str("MaxDurationExceeded"),
Self::IdleTimeout => f.write_str("IdleTimeout"),
Self::DrainRequested => f.write_str("DrainRequested"),
Self::Signal => f.write_str("Signal"),
Self::InternalError => f.write_str("InternalError"),
}
}
}
impl ActiveModelBehavior for ActiveModel {}