durable_db/entity/
task.rs1use super::sea_orm_active_enums::TaskStatus;
4use sea_orm::entity::prelude::*;
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
8#[sea_orm(schema_name = "durable", table_name = "task")]
9pub struct Model {
10 #[sea_orm(primary_key, auto_increment = false)]
11 pub id: Uuid,
12 pub parent_id: Option<Uuid>,
13 pub sequence: Option<i32>,
14 #[sea_orm(column_type = "Text")]
15 pub name: String,
16 pub status: TaskStatus,
17 pub kind: String,
18 #[sea_orm(column_type = "JsonBinary", nullable)]
19 pub input: Option<Json>,
20 #[sea_orm(column_type = "JsonBinary", nullable)]
21 pub output: Option<Json>,
22 #[sea_orm(column_type = "Text", nullable)]
23 pub error: Option<String>,
24 pub max_retries: i32,
25 pub retry_count: i32,
26 #[sea_orm(column_type = "Text", nullable)]
27 pub cron: Option<String>,
28 pub next_run_at: Option<DateTimeWithTimeZone>,
29 #[sea_orm(column_type = "Text", nullable)]
30 pub queue_name: Option<String>,
31 #[sea_orm(column_type = "Text", nullable)]
32 pub executor_id: Option<String>,
33 #[sea_orm(column_type = "Text", nullable)]
34 pub app_version: Option<String>,
35 pub timeout_ms: Option<i64>,
36 pub deadline_epoch_ms: Option<i64>,
37 pub created_at: DateTimeWithTimeZone,
38 pub started_at: Option<DateTimeWithTimeZone>,
39 pub completed_at: Option<DateTimeWithTimeZone>,
40}
41
42#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
43pub enum Relation {
44 #[sea_orm(
45 belongs_to = "Entity",
46 from = "Column::ParentId",
47 to = "Column::Id",
48 on_update = "NoAction",
49 on_delete = "Cascade"
50 )]
51 SelfRef,
52 #[sea_orm(
53 belongs_to = "super::task_queue::Entity",
54 from = "Column::QueueName",
55 to = "super::task_queue::Column::Name",
56 on_update = "NoAction",
57 on_delete = "NoAction"
58 )]
59 TaskQueue,
60}
61
62impl Related<super::task_queue::Entity> for Entity {
63 fn to() -> RelationDef {
64 Relation::TaskQueue.def()
65 }
66}
67
68impl ActiveModelBehavior for ActiveModel {}