- Introduced new models for `Organization` and `ReviewTask` to manage organizations and review tasks. - Implemented API endpoints for CRUD operations on organizations and tasks, including scanning organizations for repositories and PRs. - Developed a background worker for sequential processing of review tasks with priority handling and automatic retries. - Created frontend components for managing organizations and monitoring task queues, including real-time updates and filtering options. - Added comprehensive documentation for organization features and quick start guides. - Fixed UI issues and improved navigation for better user experience.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Review Task Queue model"""
|
||
|
||
from sqlalchemy import Column, Integer, String, DateTime, Enum, ForeignKey
|
||
from sqlalchemy.orm import relationship
|
||
from sqlalchemy.sql import func
|
||
from datetime import datetime
|
||
import enum
|
||
|
||
from app.database import Base
|
||
|
||
|
||
class TaskStatusEnum(str, enum.Enum):
|
||
"""Task status types"""
|
||
PENDING = "pending" # В очереди
|
||
IN_PROGRESS = "in_progress" # Выполняется
|
||
COMPLETED = "completed" # Завершено
|
||
FAILED = "failed" # Ошибка
|
||
|
||
|
||
class TaskPriorityEnum(str, enum.Enum):
|
||
"""Task priority types"""
|
||
LOW = "low"
|
||
NORMAL = "normal"
|
||
HIGH = "high"
|
||
|
||
|
||
class ReviewTask(Base):
|
||
"""Review task queue for sequential processing"""
|
||
|
||
__tablename__ = "review_tasks"
|
||
|
||
id = Column(Integer, primary_key=True, index=True)
|
||
pull_request_id = Column(Integer, ForeignKey("pull_requests.id"), nullable=False)
|
||
status = Column(Enum(TaskStatusEnum), default=TaskStatusEnum.PENDING, nullable=False, index=True)
|
||
priority = Column(Enum(TaskPriorityEnum), default=TaskPriorityEnum.NORMAL, nullable=False)
|
||
|
||
# Tracking
|
||
created_at = Column(DateTime, default=datetime.utcnow, server_default=func.now())
|
||
started_at = Column(DateTime, nullable=True) # Когда началась обработка
|
||
completed_at = Column(DateTime, nullable=True) # Когда завершилась
|
||
error_message = Column(String, nullable=True)
|
||
|
||
# Retry logic
|
||
retry_count = Column(Integer, default=0)
|
||
max_retries = Column(Integer, default=3)
|
||
|
||
# Relationships
|
||
pull_request = relationship("PullRequest", backref="review_tasks")
|
||
|
||
def __repr__(self):
|
||
return f"<ReviewTask(id={self.id}, pr_id={self.pull_request_id}, status={self.status})>"
|
||
|