redux of the worker queue
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Work queue table
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(WorkQueue::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(WorkQueue::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(WorkQueue::TaskType).text().not_null())
|
||||
.col(
|
||||
ColumnDef::new(WorkQueue::Status)
|
||||
.text()
|
||||
.not_null()
|
||||
.default("pending"),
|
||||
)
|
||||
.col(ColumnDef::new(WorkQueue::PayloadJson).text().not_null())
|
||||
.col(ColumnDef::new(WorkQueue::PipelineId).text())
|
||||
.col(
|
||||
ColumnDef::new(WorkQueue::CreatedAt)
|
||||
.date_time()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(WorkQueue::StartedAt).date_time())
|
||||
.col(ColumnDef::new(WorkQueue::CompletedAt).date_time())
|
||||
.col(ColumnDef::new(WorkQueue::Error).text())
|
||||
.col(
|
||||
ColumnDef::new(WorkQueue::RetryCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_work_queue_status_type")
|
||||
.table(WorkQueue::Table)
|
||||
.col(WorkQueue::Status)
|
||||
.col(WorkQueue::TaskType)
|
||||
.col(WorkQueue::CreatedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_work_queue_pipeline_id")
|
||||
.table(WorkQueue::Table)
|
||||
.col(WorkQueue::PipelineId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Scheduler state table
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(SchedulerState::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(SchedulerState::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(SchedulerState::JobName)
|
||||
.text()
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(SchedulerState::LastRunAt).date_time())
|
||||
.col(ColumnDef::new(SchedulerState::LastResult).text())
|
||||
.col(ColumnDef::new(SchedulerState::NextRunAt).date_time())
|
||||
.col(
|
||||
ColumnDef::new(SchedulerState::Enabled)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(true),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(SchedulerState::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(WorkQueue::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum WorkQueue {
|
||||
Table,
|
||||
Id,
|
||||
TaskType,
|
||||
Status,
|
||||
PayloadJson,
|
||||
PipelineId,
|
||||
CreatedAt,
|
||||
StartedAt,
|
||||
CompletedAt,
|
||||
Error,
|
||||
RetryCount,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum SchedulerState {
|
||||
Table,
|
||||
Id,
|
||||
JobName,
|
||||
LastRunAt,
|
||||
LastResult,
|
||||
NextRunAt,
|
||||
Enabled,
|
||||
}
|
||||
@@ -15,6 +15,7 @@ mod m20260320_000013_add_artist_monitoring;
|
||||
mod m20260320_000014_create_playlists;
|
||||
mod m20260320_000015_add_subsonic_password;
|
||||
mod m20260323_000016_remove_orphaned_artists;
|
||||
mod m20260323_000017_create_work_queue_and_scheduler;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -37,6 +38,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260320_000014_create_playlists::Migration),
|
||||
Box::new(m20260320_000015_add_subsonic_password::Migration),
|
||||
Box::new(m20260323_000016_remove_orphaned_artists::Migration),
|
||||
Box::new(m20260323_000017_create_work_queue_and_scheduler::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user