class User(BaseModel): __tablename__ = "users" username = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) def __repr__(self): return f"<User {self.username}>" def update(self): user = self.query.filter_by(username=self.username).first() if not user: raise UserNotFound(f"User {self.username} not found") user.password = self.password self.commit() def delete(self): db.session.delete(self) self.commit() def to_dict(self): d = super().to_dict() d.update({"username": self.username, "password": self.password}) return d
class Workflow(BaseModel): __tablename__ = "workflows" name = db.Column(db.String(255), nullable=False) project = db.Column(db.String(255), nullable=False) status = db.Column(db.Enum(StatusType), default=StatusType.pending, nullable=False) payload = db.Column(JSONBType, default={}) periodic = db.Column(db.Boolean, default=False) def __str__(self): return f"{self.project}.{self.name}" def __repr__(self): return f"<Workflow {self.project}.{self.name}>" def to_dict(self): d = super().to_dict() d.update({ "name": self.name, "payload": self.payload, "project": self.project, "fullname": f"{self.project}.{self.name}", "status": self.status.value, "periodic": self.periodic, }) return d
class Task(BaseModel): __tablename__ = "tasks" key = db.Column(db.String(), nullable=False) status = db.Column(db.Enum(StatusType), default=StatusType.pending, nullable=False) previous = db.Column(JSONBType, default=[]) result = db.Column(PickleType) # Relationship workflow_id = db.Column(UUIDType(binary=False), db.ForeignKey("workflows.id"), nullable=False) workflow = db.relationship("Workflow", backref=db.backref("tasks", lazy=True)) def __repr__(self): return f"<Task {self.key}>" def to_dict(self): d = super().to_dict() d.update({ "key": self.key, "status": self.status.value, "task": self.id, "previous": self.previous, "result": self.result, }) return d