Files
aiagent/backend/app/models/agent_schedule.py
renjianbo 7ee80c74b2 feat: 集成飞书通知和机器人对话系统
- 新增通知系统 (notifications 表、服务、API)
- 新增飞书定时任务结果推送 (webhook + 应用消息)
- 新增飞书应用消息发送服务 (feishu_app_service)
- 新增飞书 WebSocket 长连接事件监听 (苹果应用)
- 新增飞书账号绑定/解绑 API
- 新增橙子飞书机器人 (独立 WS 连接,固定路由到橙子助手 Agent)
- 执行记录添加 schedule_id,用户添加飞书绑定字段

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 16:17:49 +08:00

30 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Agent 定时任务表:按 cron 表达式周期执行 Agent"""
import uuid
from datetime import datetime
from sqlalchemy import Column, String, Text, Integer, DateTime, ForeignKey, Boolean
from sqlalchemy.dialects.mysql import CHAR
from app.core.database import Base
class AgentSchedule(Base):
"""Agent 定时任务 — 按 cron 表达式周期执行指定 Agent"""
__tablename__ = "agent_schedules"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()))
agent_id = Column(CHAR(36), ForeignKey("agents.id"), nullable=False, index=True, comment="关联 Agent ID")
name = Column(String(100), nullable=False, comment="任务名称")
cron_expression = Column(String(100), nullable=False, comment="cron 表达式,如 0 9 * * *")
input_message = Column(Text, nullable=False, comment="定时执行时发送的消息内容")
timezone = Column(String(64), default="Asia/Shanghai", comment="时区")
webhook_url = Column(String(512), nullable=True, comment="飞书机器人 Webhook URL可选执行完成后推送通知")
enabled = Column(Boolean, default=True, comment="是否启用")
last_run_at = Column(DateTime, nullable=True, comment="上次执行时间")
last_run_status = Column(String(32), nullable=True, comment="上次执行状态: success/failed")
next_run_at = Column(DateTime, nullable=False, comment="下次执行时间")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, index=True, comment="创建者 ID")
created_at = Column(DateTime, default=datetime.utcnow, comment="创建时间")
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment="更新时间")
def __repr__(self):
return f"<AgentSchedule(id={self.id}, name={self.name}, cron={self.cron_expression})>"