Skip to content

Commit

Permalink
Add task entity
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Nov 28, 2023
1 parent cd6c15a commit 0a566c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod accounts;
pub mod subscriptions;
pub mod users;
pub mod users_accounts;
pub mod tasks;
1 change: 1 addition & 0 deletions src/entity/prelude.rs
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 37 additions & 0 deletions src/entity/tasks.rs
Original file line number Diff line number Diff line change
@@ -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<DateTimeWithTimeZone>,
pub scheduled_at: Option<DateTimeWithTimeZone>,
#[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 {}

0 comments on commit 0a566c1

Please sign in to comment.