2024-01-31 19:37:01 +10:00
|
|
|
from typing import List
|
|
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
|
|
|
|
from app.models.task import Task
|
|
|
|
from app.models.user import User
|
|
|
|
from app.extensions import db
|
|
|
|
|
|
|
|
class Session(db.Model):
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
|
|
name: Mapped[str] = mapped_column(unique=True)
|
|
|
|
|
|
|
|
authorized: Mapped[bool]
|
2024-02-01 19:08:48 +10:00
|
|
|
users: Mapped[List[User]] = relationship("User", cascade="all, delete-orphan", back_populates="session")
|
2024-01-31 19:37:01 +10:00
|
|
|
|
2024-02-01 19:08:48 +10:00
|
|
|
tasks: Mapped[List[Task]] = relationship("Task", cascade="all, delete-orphan", back_populates="session")
|
2024-01-31 19:37:01 +10:00
|
|
|
|
|
|
|
def has_depending_tasks(self):
|
|
|
|
tasks = Task.query \
|
|
|
|
.filter_by(session_id=self.id) \
|
2024-02-03 22:29:56 +10:00
|
|
|
.filter((Task.status == "RUNNING") | (Task.status == "CREATED") | (Task.status == "STOPING")) \
|
2024-01-31 19:37:01 +10:00
|
|
|
.all()
|
|
|
|
|
|
|
|
return len(tasks) > 0
|