Skip to main content

chronon_core/models/
lease.rs

1//! Distributed run lease model.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// Lease for a distributed run (exactly-one claim).
7///
8/// Persisted by [`SchedulerStore`](crate::store::SchedulerStore) backends that track worker
9/// claims separately from the [`Run`](crate::models::Run) row. Used for reclaim and failover
10/// when a worker stops renewing.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Lease {
13    /// Unique lease row id.
14    pub lease_id: String,
15    /// Run this lease protects.
16    pub run_id: String,
17    /// Owning job, when the run was spawned from a schedule.
18    pub job_id: Option<String>,
19    /// Worker or coordinator instance that holds the lease.
20    pub leased_by: String,
21    /// Worker pool that may claim this run.
22    pub pool_id: String,
23    /// Lease expiry; another worker may reclaim after this instant.
24    pub lease_until: DateTime<Utc>,
25    /// When the lease row was first created.
26    pub created_at: DateTime<Utc>,
27}