Major architectural improvement to replace in-memory task storage with database-backed persistence while maintaining backward compatibility. Changes: - Created Task SQLAlchemy model matching database schema - Added Workflow and Execution SQLAlchemy models - Created TaskService for database CRUD operations - Updated UnifiedCoordinator to use database persistence - Modified task APIs to leverage database storage - Added task loading from database on coordinator initialization - Implemented status change persistence during task execution - Enhanced task cleanup with database support - Added comprehensive task statistics from database Benefits: - Tasks persist across application restarts - Better scalability and reliability - Historical task data retention - Comprehensive task filtering and querying - Maintains in-memory cache for performance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""
|
|
Task model for SQLAlchemy ORM
|
|
"""
|
|
|
|
from sqlalchemy import Column, String, Text, Integer, DateTime, ForeignKey, UUID as SqlUUID
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from ..core.database import Base
|
|
import uuid
|
|
|
|
|
|
class Task(Base):
|
|
__tablename__ = "tasks"
|
|
|
|
# Primary identification
|
|
id = Column(SqlUUID(as_uuid=True), primary_key=True, index=True, default=uuid.uuid4)
|
|
|
|
# Task details
|
|
title = Column(String(255), nullable=False)
|
|
description = Column(Text)
|
|
priority = Column(Integer, default=5)
|
|
status = Column(String(50), default='pending')
|
|
|
|
# Relationships
|
|
assigned_agent_id = Column(String(255), ForeignKey("agents.id"), nullable=True)
|
|
workflow_id = Column(SqlUUID(as_uuid=True), ForeignKey("workflows.id"), nullable=True)
|
|
execution_id = Column(SqlUUID(as_uuid=True), ForeignKey("executions.id"), nullable=True)
|
|
|
|
# Metadata and context
|
|
metadata = Column(JSONB, nullable=True)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
started_at = Column(DateTime(timezone=True), nullable=True)
|
|
completed_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
# Relationships
|
|
assigned_agent = relationship("Agent", back_populates="tasks")
|
|
workflow = relationship("Workflow", back_populates="tasks")
|
|
execution = relationship("Execution", back_populates="tasks") |