righvalor 0.1.0

RighValor: AI Infrastructure and Applications Framework for the Far Edge
use ractor_cluster::RactorClusterMessage;
use righ_dm_rs::RighIpv4Addr;
use serde::{Deserialize, Serialize};

use crate::{
    common::task::{ValorMasterTask, ValorTaskError, ValorTaskOutput, ValorTaskStatus},
    types::ValorID,
    worker::ValorWorkerEvent,
};

/// Task status update message
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TaskStatusUpdate {
    pub task_id: String,
    pub worker_id: ValorID,
    pub status: ValorTaskStatus,
    pub output: Option<ValorTaskOutput>,
    pub error: Option<ValorTaskError>,
}

/// Messages that Master can receive from Valor Workers and external systems.
///
/// These messages implement the southbound communication protocol where
/// workers report status, request registration, and provide operational updates.
#[derive(Debug, Clone, RactorClusterMessage)]
pub enum ValorMasterMessage {
    /// Southbound: Register a new worker
    SouthboundRegisterWorker(ValorID, RighIpv4Addr),
    /// Southbound: Unregister a worker
    SouthboundUnregisterWorker(ValorID),
    /// Southbound: Worker state update
    SouthboundWorkerStateUpdate(ValorWorkerEvent),
    /// Internal: Worker actor reference resolved via stable name
    InternalWorkerRefResolved(ValorID, String),
    /// Internal: Periodic cleanup tick for registry maintenance
    InternalCleanupTick,

    // Task management messages
    /// Create a new task
    CreateTask(ValorMasterTask),
    /// Update task status (from worker)
    UpdateTaskStatus(TaskStatusUpdate),
    /// Cancel a task
    CancelTask(String),
    /// Get task status
    GetTask(String),
    /// List all tasks
    ListTasks,
}