use async_trait::async_trait; use sea_orm::entity::prelude::*; pub use crate::task::{ SubscriberTask, SubscriberTaskType, SubscriberTaskTypeEnum, SubscriberTaskTypeVariant, SubscriberTaskTypeVariantIter, }; #[derive(Clone, Debug, PartialEq, Eq, DeriveActiveEnum, EnumIter, DeriveDisplay)] #[sea_orm(rs_type = "String", db_type = "Text")] pub enum SubscriberTaskStatus { #[sea_orm(string_value = "Pending")] Pending, #[sea_orm(string_value = "Scheduled")] Scheduled, #[sea_orm(string_value = "Running")] Running, #[sea_orm(string_value = "Done")] Done, #[sea_orm(string_value = "Failed")] Failed, #[sea_orm(string_value = "Killed")] Killed, } #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] #[sea_orm(table_name = "subscriber_tasks")] pub struct Model { #[sea_orm(primary_key)] pub id: String, pub subscriber_id: i32, pub job: SubscriberTask, pub task_type: SubscriberTaskType, pub status: SubscriberTaskStatus, pub attempts: i32, pub max_attempts: i32, pub run_at: DateTimeUtc, pub last_error: Option, pub lock_at: Option, pub lock_by: Option, pub done_at: Option, pub priority: i32, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { #[sea_orm( belongs_to = "super::subscribers::Entity", from = "Column::SubscriberId", to = "super::subscribers::Column::Id", on_update = "Cascade", on_delete = "Cascade" )] Subscriber, } impl Related for Entity { fn to() -> RelationDef { Relation::Subscriber.def() } } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] pub enum RelatedEntity { #[sea_orm(entity = "super::subscribers::Entity")] Subscriber, } #[async_trait] impl ActiveModelBehavior for ActiveModel {}