Vapora/crates/vapora-workflow-engine/src/error.rs
Jesús Pérez bb55c80d2b
feat(workflow-engine): autonomous scheduling with timezone and distributed lock
Add cron-based autonomous workflow firing with two hardening layers:

  - Timezone-aware scheduling via chrono-tz: ScheduledWorkflow.timezone
    (IANA identifier), compute_next_fire_at/after_tz, validate_timezone;
    DST-safe, UTC fallback when absent; validated at config load and REST API

  - Distributed fire-lock via SurrealDB conditional UPDATE (locked_by/locked_at
    fields, 120 s TTL); WorkflowScheduler gains instance_id (UUID) as lock owner;
    prevents double-fires across multi-instance deployments without extra infra

  - ScheduleStore: try_acquire_fire_lock, release_fire_lock (own-instance guard),
    full CRUD (load_one/all, full_upsert, patch, delete, load_runs)

  - REST: 7 endpoints (GET/PUT/PATCH/DELETE schedules, runs history, manual fire)
    with timezone field in all request/response types

  - Migrations 010 (schedule tables) + 011 (timezone + lock columns)
  - Tests: 48 passing (was 26); ADR-0034; changelog; feature docs updated
2026-02-26 11:34:44 +00:00

78 lines
1.9 KiB
Rust

use thiserror::Error;
#[derive(Error, Debug)]
pub enum WorkflowError {
#[error("Workflow not found: {0}")]
WorkflowNotFound(String),
#[error("Configuration error: {0}")]
ConfigError(#[from] ConfigError),
#[error("Invalid state transition: {from:?} -> {to:?}")]
InvalidTransition { from: String, to: String },
#[error("No current stage available")]
NoCurrentStage,
#[error("No agents configured for stage")]
NoAgentsInStage,
#[error("Task not found: {0}")]
TaskNotFound(String),
#[error("Stage not waiting for approval")]
NotWaitingApproval,
#[error("Swarm coordination error: {0}")]
SwarmError(String),
#[error("NATS messaging error: {0}")]
NatsError(Box<dyn std::error::Error + Send + Sync>),
#[error("Knowledge graph error: {0}")]
KnowledgeGraphError(String),
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Artifact persistence failed: {0}")]
ArtifactError(String),
#[error("Database error: {0}")]
DatabaseError(String),
#[error("Authorization denied: {0}")]
Unauthorized(String),
#[error("Internal error: {0}")]
Internal(String),
#[error("Schedule error: {0}")]
Schedule(#[from] ScheduleError),
}
#[derive(Error, Debug)]
pub enum ScheduleError {
#[error("Invalid cron expression '{expr}': {reason}")]
InvalidCron { expr: String, reason: String },
#[error("Schedule not found: {0}")]
NotFound(String),
}
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("Failed to read config file: {0}")]
IoError(#[from] std::io::Error),
#[error("Failed to parse TOML: {0}")]
Parse(#[from] toml::de::Error),
#[error("Invalid configuration: {0}")]
Invalid(String),
}
pub type Result<T> = std::result::Result<T, WorkflowError>;