From 0a566c134bae0a5dd51290462c5d355efdbd861a Mon Sep 17 00:00:00 2001 From: Jake Meyer Date: Mon, 27 Nov 2023 20:46:58 -0800 Subject: [PATCH] Add task entity --- src/entity/mod.rs | 1 + src/entity/prelude.rs | 1 + src/entity/tasks.rs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/entity/tasks.rs diff --git a/src/entity/mod.rs b/src/entity/mod.rs index e04499f..f10125e 100644 --- a/src/entity/mod.rs +++ b/src/entity/mod.rs @@ -4,3 +4,4 @@ pub mod accounts; pub mod subscriptions; pub mod users; pub mod users_accounts; +pub mod tasks; diff --git a/src/entity/prelude.rs b/src/entity/prelude.rs index cf85ede..385d504 100644 --- a/src/entity/prelude.rs +++ b/src/entity/prelude.rs @@ -1,4 +1,5 @@ pub use super::accounts::Entity as Accounts; pub use super::subscriptions::Entity as Subscriptions; +pub use super::tasks::Entity as Tasks; pub use super::users::Entity as Users; pub use super::users_accounts::Entity as UsersAccounts; diff --git a/src/entity/tasks.rs b/src/entity/tasks.rs new file mode 100644 index 0000000..f6bdec6 --- /dev/null +++ b/src/entity/tasks.rs @@ -0,0 +1,37 @@ +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter, DeriveActiveEnum)] +#[sea_orm(rs_type = "i16", db_type = "Integer")] +pub enum TaskState { + Created = 0, + Scheduled = 1, + Running = 2, + Failed = 3, + Canceled = 4, + Completed = 5, +} + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[sea_orm(table_name = "tasks")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub state: TaskState, + pub priority: i16, + pub attempt: i16, + pub max_attempts: i16, + pub created_at: DateTimeWithTimeZone, + pub attempted_at: Option, + pub scheduled_at: Option, + #[sea_orm(column_type = "Text")] + pub queue: String, + #[sea_orm(column_type = "Text")] + pub name: String, + pub payload: Json, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {}