27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
from sqlalchemy import Column, Integer, String, Text, DateTime, JSON, ForeignKey, func
|
|
from sqlalchemy.orm import relationship
|
|
from app.database import Base
|
|
|
|
class Task(Base):
|
|
"""Background Task Model"""
|
|
__tablename__ = "tasks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
task_type = Column(String(50), nullable=False, comment="Task type (e.g., 'nasa_download')")
|
|
status = Column(String(20), nullable=False, default='pending', index=True, comment="pending, running, completed, failed, cancelled")
|
|
description = Column(String(255), nullable=True)
|
|
params = Column(JSON, nullable=True, comment="Input parameters")
|
|
result = Column(JSON, nullable=True, comment="Output results")
|
|
progress = Column(Integer, default=0, comment="Progress 0-100")
|
|
error_message = Column(Text, nullable=True)
|
|
|
|
created_by = Column(Integer, nullable=True, comment="User ID")
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
started_at = Column(DateTime(timezone=True), nullable=True)
|
|
completed_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
def __repr__(self):
|
|
return f"<Task(id={self.id}, type='{self.task_type}', status='{self.status}')>"
|