22 lines
690 B
Python
22 lines
690 B
Python
from typing import List
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.task import Task
|
|
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]
|
|
|
|
tasks: Mapped[List[Task]] = relationship("Task", cascade="all, delete-orphan", back_populates="session")
|
|
|
|
def has_depending_tasks(self):
|
|
tasks = Task.query \
|
|
.filter_by(session_id=self.id) \
|
|
.filter((Task.status == "RUNNING") | (Task.status == "CREATED") | (Task.status == "STOPING")) \
|
|
.all()
|
|
|
|
return len(tasks) > 0
|