You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

task.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from datetime import datetime
  2. from typing import Optional
  3. from celery import states # type: ignore
  4. from sqlalchemy import DateTime, String
  5. from sqlalchemy.orm import Mapped, mapped_column
  6. from libs.datetime_utils import naive_utc_now
  7. from models.base import Base
  8. from .engine import db
  9. class CeleryTask(Base):
  10. """Task result/status."""
  11. __tablename__ = "celery_taskmeta"
  12. id = mapped_column(db.Integer, db.Sequence("task_id_sequence"), primary_key=True, autoincrement=True)
  13. task_id = mapped_column(String(155), unique=True)
  14. status = mapped_column(String(50), default=states.PENDING)
  15. result = mapped_column(db.PickleType, nullable=True)
  16. date_done = mapped_column(
  17. DateTime,
  18. default=lambda: naive_utc_now(),
  19. onupdate=lambda: naive_utc_now(),
  20. nullable=True,
  21. )
  22. traceback = mapped_column(db.Text, nullable=True)
  23. name = mapped_column(String(155), nullable=True)
  24. args = mapped_column(db.LargeBinary, nullable=True)
  25. kwargs = mapped_column(db.LargeBinary, nullable=True)
  26. worker = mapped_column(String(155), nullable=True)
  27. retries: Mapped[Optional[int]] = mapped_column(db.Integer, nullable=True)
  28. queue = mapped_column(String(155), nullable=True)
  29. class CeleryTaskSet(Base):
  30. """TaskSet result."""
  31. __tablename__ = "celery_tasksetmeta"
  32. id: Mapped[int] = mapped_column(
  33. db.Integer, db.Sequence("taskset_id_sequence"), autoincrement=True, primary_key=True
  34. )
  35. taskset_id = mapped_column(String(155), unique=True)
  36. result = mapped_column(db.PickleType, nullable=True)
  37. date_done: Mapped[Optional[datetime]] = mapped_column(DateTime, default=lambda: naive_utc_now(), nullable=True)