dify/api/models/task.py

41 lines
1.5 KiB
Python
Raw Normal View History

from datetime import datetime, timezone
2023-05-15 08:51:32 +08:00
from celery import states
from extensions.ext_database import db
2023-05-15 08:51:32 +08:00
class CeleryTask(db.Model):
"""Task result/status."""
__tablename__ = "celery_taskmeta"
2023-05-15 08:51:32 +08:00
id = db.Column(db.Integer, db.Sequence("task_id_sequence"), primary_key=True, autoincrement=True)
2023-05-15 08:51:32 +08:00
task_id = db.Column(db.String(155), unique=True)
status = db.Column(db.String(50), default=states.PENDING)
result = db.Column(db.PickleType, nullable=True)
date_done = db.Column(
db.DateTime,
default=lambda: datetime.now(timezone.utc).replace(tzinfo=None),
onupdate=lambda: datetime.now(timezone.utc).replace(tzinfo=None),
nullable=True,
)
2023-05-15 08:51:32 +08:00
traceback = db.Column(db.Text, nullable=True)
name = db.Column(db.String(155), nullable=True)
args = db.Column(db.LargeBinary, nullable=True)
kwargs = db.Column(db.LargeBinary, nullable=True)
worker = db.Column(db.String(155), nullable=True)
retries = db.Column(db.Integer, nullable=True)
queue = db.Column(db.String(155), nullable=True)
class CeleryTaskSet(db.Model):
"""TaskSet result."""
__tablename__ = "celery_tasksetmeta"
2023-05-15 08:51:32 +08:00
id = db.Column(db.Integer, db.Sequence("taskset_id_sequence"), autoincrement=True, primary_key=True)
2023-05-15 08:51:32 +08:00
taskset_id = db.Column(db.String(155), unique=True)
result = db.Column(db.PickleType, nullable=True)
date_done = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc).replace(tzinfo=None), nullable=True)