Skip to main content

chronon_core/models/
worker.rs

1//! Registered worker instances.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7/// Worker registration status.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
9#[serde(rename_all = "lowercase")]
10pub enum WorkerStatus {
11    /// Accepting new run claims.
12    #[default]
13    Online,
14    /// Finishing in-flight runs but not claiming new work.
15    Draining,
16    /// Not heartbeating; excluded from placement.
17    Offline,
18}
19
20/// Registered Chronon worker instance (heartbeat).
21///
22/// Workers register at startup and send periodic heartbeats so coordinators can detect
23/// stale capacity and route claims to live pools.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Worker {
26    /// Stable worker instance id.
27    pub worker_id: String,
28    /// Execution pool this worker serves (matches [`Run::pool_id`](crate::models::Run::pool_id)).
29    pub pool_id: String,
30    /// Optional placement cell / availability zone label.
31    pub cell_id: Option<String>,
32    /// Whether the worker accepts new claims.
33    pub status: WorkerStatus,
34    /// Last heartbeat timestamp (updated by [`SchedulerStore::heartbeat_worker`](crate::store::SchedulerStore::heartbeat_worker)).
35    pub last_heartbeat_at: DateTime<Utc>,
36    /// Opaque capacity hints (concurrency limits, CPU, etc.).
37    pub capacity_json: Option<Value>,
38    /// Row creation time.
39    pub created_at: DateTime<Utc>,
40    /// Last metadata update.
41    pub updated_at: DateTime<Utc>,
42}