feat(调度任务): 实现调度任务管理功能
新增调度任务模块,支持任务的增删改查、启停及手动执行 - 后端添加 schedule_job 模型、服务、路由及调度器工具类 - 前端新增调度任务管理页面 - 修改 flow 相关接口将 id 类型从 String 改为 i64 - 添加 tokio-cron-scheduler 依赖实现定时任务调度 - 初始化时加载已启用任务并注册到调度器
This commit is contained in:
@ -23,6 +23,8 @@ mod m20220101_000016_add_unique_index_to_flows_code;
|
||||
mod m20220101_000017_create_flow_run_logs;
|
||||
// 新增:为 flow_run_logs 添加 flow_code 列
|
||||
mod m20220101_000018_add_flow_code_to_flow_run_logs;
|
||||
// 新增:计划任务表
|
||||
mod m20220101_000019_create_schedule_jobs;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@ -55,6 +57,8 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20220101_000017_create_flow_run_logs::Migration),
|
||||
// 新增:为 flow_run_logs 添加 flow_code 列
|
||||
Box::new(m20220101_000018_add_flow_code_to_flow_run_logs::Migration),
|
||||
// 新增:计划任务表
|
||||
Box::new(m20220101_000019_create_schedule_jobs::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(ScheduleJobs::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(ScheduleJobs::Id).string_len(64).not_null().primary_key())
|
||||
.col(ColumnDef::new(ScheduleJobs::Name).string().not_null())
|
||||
.col(ColumnDef::new(ScheduleJobs::CronExpr).string().not_null())
|
||||
.col(ColumnDef::new(ScheduleJobs::Enabled).boolean().not_null().default(false))
|
||||
.col(ColumnDef::new(ScheduleJobs::FlowCode).string().not_null())
|
||||
.col(ColumnDef::new(ScheduleJobs::CreatedAt).timestamp().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(ScheduleJobs::UpdatedAt).timestamp().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.drop_table(Table::drop().table(ScheduleJobs::Table).to_owned()).await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum ScheduleJobs {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
CronExpr,
|
||||
Enabled,
|
||||
FlowCode,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
Reference in New Issue
Block a user