asynq 0.1.8

Simple, reliable & efficient distributed task queue in Rust, inspired by hibiken/asynq
Documentation
//! 工作者实体
//! Worker entity

use sea_orm::entity::prelude::*;

/// 工作者状态枚举
/// Worker status enum
#[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,
}

/// 工作者实体模型
/// Worker entity model
#[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,
  /// 租户 ID,用于多租户隔离
  /// Tenant ID for multi-tenancy isolation
  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 {}