Source code for sidequest_common.models.sims

 1"""A queued/running/finished gear-swap sim job, run through the wowsims/forever CLI.
 2
 3Requested from the bot's ``#sim`` forum and claimed one at a time per pod by the sim runner
 4(``api/src/sidequest_api/domain/sims/runner.py``). Finished rows (``done`` or ``failed``) older than 7 days are
 5deleted by the runner; see ``website/src/pages/privacy/index.astro``.
 6"""
 7
 8from datetime import datetime  # SQLAlchemy resolves Mapped[] annotations at runtime
 9
10from advanced_alchemy.base import UUIDAuditBase
11from advanced_alchemy.types import DateTimeUTC, JsonB
12from sqlalchemy import Boolean, String, Text
13from sqlalchemy.orm import Mapped, mapped_column
14
15
[docs] 16class SimJob(UUIDAuditBase): 17 """One sim request: the request body, its status, and its result once done.""" 18 19 __tablename__ = "sim_job" 20 __table_args__ = { 21 "comment": ( 22 "Gear-swap sim jobs run through the wowsims/forever CLI, requested by the bot's #sim forum. " 23 "Finished rows are deleted after 7 days." 24 ) 25 } 26 27 request: Mapped[dict] = mapped_column(JsonB, doc="The SimRequest body, as the bot sent it.") 28 status: Mapped[str] = mapped_column( 29 String(20), default="queued", index=True, doc="queued, running, done, or failed." 30 ) 31 result: Mapped[dict | None] = mapped_column(JsonB, default=None, doc="The SimResult body, once status is done.") 32 error: Mapped[str | None] = mapped_column(Text, default=None, doc="A plain-English failure reason, if failed.") 33 requested_by: Mapped[str | None] = mapped_column( 34 String(32), default=None, index=True, doc="The Discord user id that asked for this sim, for rate limiting." 35 ) 36 started_at: Mapped[datetime | None] = mapped_column( 37 DateTimeUTC(timezone=True), default=None, doc="When the runner claimed this job." 38 ) 39 finished_at: Mapped[datetime | None] = mapped_column( 40 DateTimeUTC(timezone=True), default=None, doc="When this job reached done or failed." 41 ) 42 requeued: Mapped[bool] = mapped_column( 43 Boolean, default=False, doc="Whether this job was already once requeued after running too long." 44 )