mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
feat(automation): add SQLAlchemy models for the three v1 tables
Three enums (one file each) plus three models (one file each), all
under app/automations/persistence/. The module imports from app.db
only (Base/BaseModel/TimestampMixin and FK targets searchspaces.id /
user.id); no business-logic imports.
Enums:
- AutomationStatus: active | paused | archived
- RunStatus: pending | running | succeeded | failed | cancelled
| timed_out
- TriggerType: schedule | manual (Phase-2/3 add webhook | event)
Models:
- Automation: search_space-scoped, created_by_user_id (SET NULL),
name + description, status enum, definition JSONB, version int,
updated_at with onupdate.
- AutomationTrigger: FK → automations (CASCADE), type enum, config
JSONB, enabled bool, last_fired_at. Webhook secret_hash is omitted
until Phase 2.
- AutomationRun: FK → automations (CASCADE), nullable trigger_id
(SET NULL — null = manual via UI), status enum,
definition_snapshot for immutable history, trigger_payload /
resolved_inputs / step_results / output / artifacts / error JSONB
columns, started_at / finished_at timestamps, agent_session_id for
linking to the LangGraph trace. cost_usd column omitted until at
least one v1 capability records token-level cost.
Verified: Base.metadata exposes all three table names; columns and
enums introspect as documented; no linter errors.
This commit is contained in:
parent
113748dfd5
commit
05931375f4
9 changed files with 300 additions and 3 deletions
|
|
@ -2,4 +2,12 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
__all__: list[str] = []
|
||||
from .automation_status import AutomationStatus
|
||||
from .run_status import RunStatus
|
||||
from .trigger_type import TriggerType
|
||||
|
||||
__all__ = [
|
||||
"AutomationStatus",
|
||||
"RunStatus",
|
||||
"TriggerType",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
"""``AutomationStatus`` — lifecycle of a stored automation definition."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class AutomationStatus(StrEnum):
|
||||
"""Status of an automation in the registry.
|
||||
|
||||
``active`` — eligible to fire from its triggers.
|
||||
``paused`` — definition retained, triggers do not fire.
|
||||
``archived`` — kept for run history only; no edits, no fires.
|
||||
"""
|
||||
|
||||
ACTIVE = "active"
|
||||
PAUSED = "paused"
|
||||
ARCHIVED = "archived"
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
"""``RunStatus`` — the state machine of a single ``AutomationRun``."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class RunStatus(StrEnum):
|
||||
"""Lifecycle states of an ``AutomationRun`` row.
|
||||
|
||||
Transitions are linear with three terminal branches:
|
||||
|
||||
pending → running → (succeeded | failed | cancelled | timed_out)
|
||||
|
||||
``pending`` — row created, executor task enqueued, work not started.
|
||||
``running`` — executor has picked up the run.
|
||||
``succeeded`` — terminal: plan completed without error.
|
||||
``failed`` — terminal: at least one step raised an unrecoverable error.
|
||||
``cancelled`` — terminal: caller asked for cancellation.
|
||||
``timed_out`` — terminal: run exceeded its configured timeout.
|
||||
"""
|
||||
|
||||
PENDING = "pending"
|
||||
RUNNING = "running"
|
||||
SUCCEEDED = "succeeded"
|
||||
FAILED = "failed"
|
||||
CANCELLED = "cancelled"
|
||||
TIMED_OUT = "timed_out"
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
"""``TriggerType`` — the trigger-kind discriminator (v1 = schedule, manual)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class TriggerType(StrEnum):
|
||||
"""Kind of trigger an ``AutomationTrigger`` row represents.
|
||||
|
||||
v1 ships two kinds:
|
||||
|
||||
``schedule`` — fires on a cron expression managed by Celery Beat.
|
||||
``manual`` — fires on demand from the UI's "Run now" affordance.
|
||||
|
||||
``webhook`` and ``event`` are deferred to Phase 2 and Phase 3
|
||||
respectively; adding them is an enum-value extension only.
|
||||
"""
|
||||
|
||||
SCHEDULE = "schedule"
|
||||
MANUAL = "manual"
|
||||
Loading…
Add table
Add a link
Reference in a new issue