- 新增 AgentSchedule 模型、CRUD API、调度服务 - 集成 Celery Beat 每分钟检查到期任务并自动触发执行 - 支持手动触发、cron 表达式解析、执行状态跟踪 - 依赖: croniter (cron 表达式解析) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
890 B
Python
37 lines
890 B
Python
"""
|
|
Celery 应用配置
|
|
"""
|
|
from celery import Celery
|
|
from celery.schedules import crontab
|
|
from app.core.config import settings
|
|
|
|
celery_app = Celery(
|
|
"aiagent",
|
|
broker=settings.REDIS_URL,
|
|
backend=settings.REDIS_URL,
|
|
include=[
|
|
"app.tasks.workflow_tasks",
|
|
"app.tasks.agent_tasks",
|
|
"app.tasks.scheduler_tasks",
|
|
]
|
|
)
|
|
|
|
celery_app.conf.update(
|
|
task_serializer="json",
|
|
accept_content=["json"],
|
|
result_serializer="json",
|
|
timezone="Asia/Shanghai",
|
|
enable_utc=True,
|
|
task_track_started=True,
|
|
task_time_limit=30 * 60, # 30分钟
|
|
task_soft_time_limit=25 * 60, # 25分钟
|
|
)
|
|
|
|
# Celery Beat 定时调度配置
|
|
celery_app.conf.beat_schedule = {
|
|
"check-agent-schedules-every-minute": {
|
|
"task": "app.tasks.scheduler_tasks.check_agent_schedules_task",
|
|
"schedule": crontab(minute="*"), # 每分钟检查
|
|
},
|
|
}
|