use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(50))")]
pub enum WorkerStatus {
#[sea_orm(string_value = "active")]
Active,
#[sea_orm(string_value = "idle")]
Idle,
#[sea_orm(string_value = "stopped")]
Stopped,
}
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "asynq_workers")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub server_id: String,
pub queue: String,
pub task_id: Option<String>,
pub task_type: Option<String>,
#[sea_orm(column_type = "VarBinary(StringLen::None)", nullable)]
pub task_payload: Option<Vec<u8>>,
pub status: WorkerStatus,
pub started_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub tenant_id: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::servers::Entity",
from = "Column::ServerId",
to = "super::servers::Column::Id"
)]
Server,
#[sea_orm(
belongs_to = "super::queues::Entity",
from = "Column::Queue",
to = "super::queues::Column::Name"
)]
Queue,
#[sea_orm(
belongs_to = "super::tasks::Entity",
from = "Column::TaskId",
to = "super::tasks::Column::Id"
)]
Task,
}
impl Related<super::servers::Entity> for Entity {
fn to() -> RelationDef {
Relation::Server.def()
}
}
impl Related<super::queues::Entity> for Entity {
fn to() -> RelationDef {
Relation::Queue.def()
}
}
impl Related<super::tasks::Entity> for Entity {
fn to() -> RelationDef {
Relation::Task.def()
}
}
impl ActiveModelBehavior for ActiveModel {}