Files
dify/api/models/task.py
T

48 lines
1.6 KiB
Python
Raw Normal View History

2025-07-23 01:39:59 +09:00
from datetime import datetime
import sqlalchemy as sa
from celery import states
2025-07-31 19:43:04 +09:00
from sqlalchemy import DateTime, String
2025-07-23 01:39:59 +09:00
from sqlalchemy.orm import Mapped, mapped_column
from libs.datetime_utils import naive_utc_now
+109
2025-02-17 17:05:13 +08:00
from models.base import Base
from .engine import db
2023-05-15 08:51:32 +08:00
+109
2025-02-17 17:05:13 +08:00
class CeleryTask(Base):
2023-05-15 08:51:32 +08:00
"""Task result/status."""
__tablename__ = "celery_taskmeta"
2023-05-15 08:51:32 +08:00
id = mapped_column(sa.Integer, sa.Sequence("task_id_sequence"), primary_key=True, autoincrement=True)
2025-07-31 19:43:04 +09:00
task_id = mapped_column(String(155), unique=True)
status = mapped_column(String(50), default=states.PENDING)
2025-07-23 01:39:59 +09:00
result = mapped_column(db.PickleType, nullable=True)
date_done = mapped_column(
2025-07-31 19:43:04 +09:00
DateTime,
default=lambda: naive_utc_now(),
onupdate=lambda: naive_utc_now(),
nullable=True,
)
traceback = mapped_column(sa.Text, nullable=True)
2025-07-31 19:43:04 +09:00
name = mapped_column(String(155), nullable=True)
args = mapped_column(sa.LargeBinary, nullable=True)
kwargs = mapped_column(sa.LargeBinary, nullable=True)
2025-07-31 19:43:04 +09:00
worker = mapped_column(String(155), nullable=True)
retries: Mapped[int | None] = mapped_column(sa.Integer, nullable=True)
2025-07-31 19:43:04 +09:00
queue = mapped_column(String(155), nullable=True)
2023-05-15 08:51:32 +08:00
+109
2025-02-17 17:05:13 +08:00
class CeleryTaskSet(Base):
2023-05-15 08:51:32 +08:00
"""TaskSet result."""
__tablename__ = "celery_tasksetmeta"
2023-05-15 08:51:32 +08:00
2025-07-23 01:39:59 +09:00
id: Mapped[int] = mapped_column(
sa.Integer, sa.Sequence("taskset_id_sequence"), autoincrement=True, primary_key=True
2025-07-23 01:39:59 +09:00
)
2025-07-31 19:43:04 +09:00
taskset_id = mapped_column(String(155), unique=True)
2025-07-23 01:39:59 +09:00
result = mapped_column(db.PickleType, nullable=True)
date_done: Mapped[datetime | None] = mapped_column(DateTime, default=lambda: naive_utc_now(), nullable=True)