Skip to main content

nautilus_persistence/writer/
run.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8// -------------------------------------------------------------------------------------------------
9
10//! Shared staged-writer session and run-state types.
11
12use nautilus_common::enums::Environment;
13
14use crate::common::storage::StorageBackend;
15
16#[derive(Clone)]
17pub struct FeatherSessionSource {
18    pub storage: StorageBackend,
19    pub environment: Environment,
20    pub instance_id: String,
21}
22
23impl FeatherSessionSource {
24    #[must_use]
25    pub fn new(
26        storage: StorageBackend,
27        environment: Environment,
28        instance_id: impl Into<String>,
29    ) -> Self {
30        Self {
31            storage,
32            environment,
33            instance_id: instance_id.into(),
34        }
35    }
36}
37
38#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
39pub enum RunStatus {
40    InProgress,
41    Completed,
42    Promoted,
43    Failed,
44}
45
46impl RunStatus {
47    #[must_use]
48    pub const fn as_str(self) -> &'static str {
49        match self {
50            Self::InProgress => "in_progress",
51            Self::Completed => "completed",
52            Self::Promoted => "promoted",
53            Self::Failed => "failed",
54        }
55    }
56
57    #[must_use]
58    pub fn from_storage_str(value: &str) -> Self {
59        match value {
60            "in_progress" => Self::InProgress,
61            "completed" => Self::Completed,
62            "promoted" => Self::Promoted,
63            "failed" => Self::Failed,
64            _ => {
65                log::warn!(
66                    "Unknown catalog run status '{value}'; treating the run as failed for recovery"
67                );
68                Self::Failed
69            }
70        }
71    }
72}