This commit is contained in:
HotSwapp
2025-08-18 20:20:04 -05:00
parent 89b2bc0aa2
commit bac8cc4bd5
114 changed files with 30258 additions and 1341 deletions

55
app/models/jobs.py Normal file
View File

@@ -0,0 +1,55 @@
"""
Simple job record schema for tracking synchronous batch operations.
"""
from sqlalchemy import Column, Integer, String, DateTime, Text, JSON, Index
from sqlalchemy.sql import func
from app.models.base import BaseModel
class JobRecord(BaseModel):
"""
Minimal job tracking record (no worker/queue yet).
Used to record outcomes and downloadable bundle info for synchronous jobs
such as batch document generation.
"""
__tablename__ = "jobs"
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
job_id = Column(String(100), unique=True, nullable=False, index=True)
job_type = Column(String(64), nullable=False, index=True) # e.g., documents_batch
status = Column(String(32), nullable=False, index=True) # running|completed|failed
# Request/identity
requested_by_username = Column(String(150), nullable=True, index=True)
# Timing
started_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False, index=True)
completed_at = Column(DateTime(timezone=True), nullable=True, index=True)
# Metrics
total_requested = Column(Integer, nullable=False, default=0)
total_success = Column(Integer, nullable=False, default=0)
total_failed = Column(Integer, nullable=False, default=0)
# Result bundle (if any)
result_storage_path = Column(String(512), nullable=True)
result_mime_type = Column(String(100), nullable=True)
result_size = Column(Integer, nullable=True)
# Arbitrary details/metadata for easy querying
details = Column(JSON, nullable=True)
__table_args__ = (
Index("ix_jobs_type_status", "job_type", "status"),
{},
)
def __repr__(self):
return (
f"<JobRecord(job_id={self.job_id}, type='{self.job_type}', status='{self.status}', "
f"success={self.total_success}/{self.total_requested})>"
)