4.8 KiB
4.8 KiB
Automation Page (AI Automation Pipeline Dashboard)
Purpose
Provide a site-scoped dashboard to configure, run, pause, resume, and monitor the 7-stage automation pipeline. Surfaces pipeline overview, current run status, metrics, history, configuration modal, and credit sufficiency checks.
Code Locations (exact paths)
- Primary page:
frontend/src/pages/Automation/AutomationPage.tsx - Service:
frontend/src/services/automationService(config, current run, estimate, pipeline overview, runNow, pause, resume, publishWithoutReview) - Metrics sources:
frontend/src/services/api(fetchKeywords,fetchClusters,fetchContentIdeas,fetchTasks,fetchContent,fetchContentImages) - UI components:
frontend/src/components/Automation/{ActivityLog,ConfigModal,RunHistory,CurrentProcessingCard},frontend/src/components/dashboard/EnhancedMetricCard,frontend/src/components/common/ComponentCard,frontend/src/components/common/PageMeta,frontend/src/components/common/DebugSiteSelector
High-Level Responsibilities
- Load automation config, current run, credit estimate, and pipeline overview for the active site.
- Poll current run and pipeline status while running/paused; refresh metrics regularly during runs.
- Provide controls: Run Now, Pause, Resume, Save Config, Publish Without Review.
- Show per-stage cards, current processing card, run history, and activity log.
Detailed Behavior
- Site binding: requires
useSiteStore.activeSite; without it, page shows a “select a site” message. - Initial load (
loadData): parallel calls togetConfig,getCurrentRun,estimate,getPipelineOverviewplus low-level metrics (keywords/clusters/ideas/tasks/content/images counts) per site_id. - Polling: 5s interval; if run status is
running/paused, refresh run, pipeline, and metrics; otherwise refresh pipeline only. - Metrics: counts for keywords (total/new/mapped), clusters (total/new/mapped), ideas (total/new/queued/completed), tasks (total), content (total/draft/review/published), images (total/pending).
- Stage cards: derived from
STAGE_CONFIGarray representing 7 pipeline stages including manual review gate. - Actions:
- Run Now: checks credit sufficiency from
estimate; blocks if insufficient. - Pause/Resume: call automationService with site + run_id, then refresh run/pipeline/metrics.
- Save Config: persists partial config, updates local state, reloads pipeline/metrics/run.
- Publish Without Review: calls
publishWithoutReviewwith confirmation prompt, then reloads.
- Run Now: checks credit sufficiency from
- UI states:
loadingspinner until initial fetch;showProcessingCardtoggled on when a run exists.
Data Structures / Models Involved (no code)
AutomationConfig: site-level automation settings (intervals, gates, etc.).AutomationRun: run_id, status (running,paused, etc.), stage info.PipelineStage: stage list with status/progress.- Metrics DTOs from planner/writer/image endpoints (
countfields only).
Execution Flow
useEffectwith site dependency →loadData.- Interval polling while active runs →
loadCurrentRun,loadPipelineOverview,loadMetrics. - User actions dispatch to automationService; toasts for success/error; follow-up refreshes.
Cross-Module Interactions
- Pulls planner/writer/image counts to present authoritative pipeline context.
- Uses
useSiteStorefor tenant/site scoping; credit checks rely on billing estimate API.
State Transitions
currentRun.statusdrives polling and control availability.showProcessingCardturns on when a run exists.estimate.sufficientgates Run Now action.
Error Handling
- Toast-based error reporting; fetch failures log to console but keep page usable.
- Metrics fetch wrapped in try/catch; failure degrades to missing metrics without blocking the rest.
Tenancy Rules
- All automation service calls require
activeSite.id; backend enforces account/site scoping. No client override for other tenants.
Billing Rules (if applicable)
- Run Now is blocked when
estimate.sufficientis false; shows required vs current credits.
Background Tasks / Schedulers (if applicable)
- Client-side polling (5s) during active runs; no background scheduling beyond that.
Key Design Considerations
- Polling keeps UI aligned with long-running Celery pipeline states.
- Credit gate prevents user-initiated runs that would immediately fail server-side.
- Metrics are read-only mirrors of backend aggregates to align UI with planner/writer state.
How Developers Should Work With This Module
- When adding new stages, extend
STAGE_CONFIGand ensure backend pipeline overview includes them. - Keep polling interval modest; if adding heavier metrics, consider staggering fetches to avoid rate limits.
- Wire new config fields through
AutomationConfigtype,ConfigModal, andupdateConfigpayload.