Phase 3: Outcome storage

- Add RandomNumberOutcome model to models.py
- Update worker.py to execute job logic:
  - Generate random number 0-100
  - Record execution duration
  - Store outcome in database
- Add test_jobs.py with unit tests for job handler logic
This commit is contained in:
counterweight 2025-12-21 22:50:35 +01:00
parent 6ca0ae88dd
commit 7beb213cf5
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 257 additions and 10 deletions

View file

@ -351,3 +351,24 @@ class Appointment(Base):
cancelled_at: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True), nullable=True
)
class RandomNumberOutcome(Base):
"""Outcome of a random number job execution."""
__tablename__ = "random_number_outcomes"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
job_id: Mapped[int] = mapped_column(Integer, nullable=False, index=True)
triggered_by_user_id: Mapped[int] = mapped_column(
Integer, ForeignKey("users.id"), nullable=False, index=True
)
triggered_by: Mapped[User] = relationship(
"User", foreign_keys=[triggered_by_user_id], lazy="joined"
)
value: Mapped[int] = mapped_column(Integer, nullable=False)
duration_ms: Mapped[int] = mapped_column(Integer, nullable=False)
status: Mapped[str] = mapped_column(String(20), nullable=False, default="completed")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(UTC)
)