Spaces:
Running
Running
Download src/models/schedule.py from arimatch1/crewhub-staging: direct link, hf CLI and curl.
- Browser
- Download file 3.04 kB
-
https://huggingface.co/spaces/arimatch1/crewhub-staging/resolve/main/src/models/schedule.py
- Command line
-
hf download hf://spaces/arimatch1/crewhub-staging/src/models/schedule.py
-
curl -L -o schedule.py https://huggingface.co/spaces/arimatch1/crewhub-staging/resolve/main/src/models/schedule.py
3.04 kB
| # Copyright (c) 2026 CrewHub. All rights reserved. | |
| # Proprietary and confidential. See LICENSE for details. | |
| """Schedule model — recurring execution of tasks, workflows, or crews.""" | |
| import uuid | |
| from datetime import datetime | |
| from decimal import Decimal | |
| from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, JSON, Numeric, String, Text, Uuid, func | |
| from sqlalchemy.orm import Mapped, mapped_column, relationship | |
| from src.database import Base | |
| class Schedule(Base): | |
| __tablename__ = "schedules" | |
| id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4) | |
| owner_id: Mapped[uuid.UUID] = mapped_column( | |
| Uuid, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True | |
| ) | |
| name: Mapped[str] = mapped_column(String(255), nullable=False) | |
| schedule_type: Mapped[str] = mapped_column(String(20), nullable=False) | |
| target_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, nullable=True) | |
| task_params: Mapped[dict | None] = mapped_column(JSON, nullable=True) | |
| cron_expression: Mapped[str] = mapped_column(String(100), nullable=False) | |
| timezone: Mapped[str] = mapped_column(String(50), nullable=False, default="UTC") | |
| input_message: Mapped[str | None] = mapped_column(Text, nullable=True) | |
| is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True) | |
| next_run_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) | |
| last_run_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) | |
| run_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0) | |
| max_runs: Mapped[int | None] = mapped_column(Integer, nullable=True) | |
| consecutive_failures: Mapped[int] = mapped_column(Integer, nullable=False, default=0) | |
| max_consecutive_failures: Mapped[int] = mapped_column(Integer, nullable=False, default=3) | |
| credit_minimum: Mapped[int] = mapped_column(Integer, nullable=False, default=0) | |
| # UCP: Credit-aware execution | |
| credit_budget_per_run: Mapped[Decimal | None] = mapped_column( | |
| Numeric(12, 4), nullable=True | |
| ) | |
| pause_reason: Mapped[str | None] = mapped_column(String(50), nullable=True) | |
| last_notified_at: Mapped[datetime | None] = mapped_column( | |
| DateTime(timezone=True), nullable=True | |
| ) | |
| last_run_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, nullable=True) | |
| total_runs: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default="0") | |
| successful_runs: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default="0") | |
| failed_runs: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default="0") | |
| total_credits_spent: Mapped[Decimal] = mapped_column( | |
| Numeric(16, 4), nullable=False, default=Decimal("0"), server_default="0" | |
| ) | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), nullable=False | |
| ) | |
| owner: Mapped["User"] = relationship("User", lazy="selectin") | |