feat: initial TaskPulse release

AI Agent 定时任务跟踪、监控、状态看板系统。

- FastAPI + Vue3 单体应用
- AI Agent 一键接入(批量注册 API)
- 暗色主题 Dashboard
- 后台调度器 + 超时告警
- 飞书/邮件/Webhook 多渠道通知
- Base URL 可配置
- Gunicorn 生产部署
This commit is contained in:
2026-06-14 22:39:23 +08:00
commit 521cf0269c
54 changed files with 6328 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
"""Alembic environment config (async)."""
import asyncio
from logging.config import fileConfig
from alembic import context
from sqlalchemy import pool
from sqlalchemy.ext.asyncio import async_engine_from_config
from app.config import settings
from app.database import Base
# Import all models so Alembic can detect them
import app.models # noqa: F401
config = context.config
config.set_main_option("sqlalchemy.url", settings.DATABASE_URL_SYNC)
if config.config_file_name is not None:
fileConfig(config.config_file_name)
target_metadata = Base.metadata
def run_migrations_offline() -> None:
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
def do_run_migrations(connection):
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
async def run_async_migrations() -> None:
from sqlalchemy.ext.asyncio import create_async_engine
connectable = create_async_engine(settings.DATABASE_URL, poolclass=pool.NullPool)
async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)
await connectable.dispose()
def run_migrations_online() -> None:
asyncio.run(run_async_migrations())
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
+111
View File
@@ -0,0 +1,111 @@
"""Alembic generic migration script."""
"""
Revision ID: 0001
Revises:
Create Date: 2025-01-01
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "0001"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"agents",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("name", sa.String(128), unique=True, nullable=False),
sa.Column("description", sa.Text, default=""),
sa.Column("api_key", sa.String(128), unique=True),
sa.Column("status", sa.String(32), default="active"),
sa.Column("last_heartbeat_at", sa.DateTime, nullable=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_table(
"notification_channels",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("name", sa.String(128), nullable=False),
sa.Column("channel_type", sa.String(32), nullable=False),
sa.Column("config", sa.Text, nullable=False),
sa.Column("enabled", sa.Boolean, default=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_table(
"scheduled_tasks",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("agent_id", sa.Integer, sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False),
sa.Column("name", sa.String(256), nullable=False),
sa.Column("description", sa.Text, default=""),
sa.Column("cron_expression", sa.String(64), nullable=False),
sa.Column("grace_period", sa.Integer, default=300),
sa.Column("status", sa.String(32), default="active"),
sa.Column("last_run_at", sa.DateTime, nullable=True),
sa.Column("last_run_result", sa.String(32), nullable=True),
sa.Column("next_run_at", sa.DateTime, nullable=True),
sa.Column("total_run_count", sa.Integer, default=0),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_table(
"task_executions",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("task_id", sa.Integer, sa.ForeignKey("scheduled_tasks.id", ondelete="CASCADE"), nullable=False),
sa.Column("agent_id", sa.Integer, sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False),
sa.Column("status", sa.String(32), default="running"),
sa.Column("started_at", sa.DateTime, server_default=sa.func.now()),
sa.Column("finished_at", sa.DateTime, nullable=True),
sa.Column("duration_ms", sa.Integer, nullable=True),
sa.Column("result", sa.Text, nullable=True),
sa.Column("log", sa.Text, nullable=True),
sa.Column("error_message", sa.Text, nullable=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_table(
"alert_rules",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("task_id", sa.Integer, sa.ForeignKey("scheduled_tasks.id", ondelete="CASCADE"), nullable=False),
sa.Column("channel_id", sa.Integer, sa.ForeignKey("notification_channels.id", ondelete="CASCADE"), nullable=False),
sa.Column("alert_type", sa.String(32), default="missed_run"),
sa.Column("enabled", sa.Boolean, default=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_table(
"alerts",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("task_id", sa.Integer, sa.ForeignKey("scheduled_tasks.id", ondelete="SET NULL"), nullable=True),
sa.Column("alert_type", sa.String(32), nullable=False),
sa.Column("message", sa.Text, nullable=False),
sa.Column("status", sa.String(32), default="pending"),
sa.Column("acknowledged_at", sa.DateTime, nullable=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_table(
"system_config",
sa.Column("key", sa.String(128), primary_key=True),
sa.Column("value", sa.Text, nullable=False),
sa.Column("description", sa.String(256), default=""),
sa.Column("updated_at", sa.DateTime, server_default=sa.func.now()),
)
def downgrade() -> None:
op.drop_table("system_config")
op.drop_table("alerts")
op.drop_table("alert_rules")
op.drop_table("task_executions")
op.drop_table("scheduled_tasks")
op.drop_table("notification_channels")
op.drop_table("agents")