couchbase_core/options/
waituntilready.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.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
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use crate::httpx::request::OnBehalfOfInfo;
20use crate::retry::RetryStrategy;
21use crate::retrybesteffort::BestEffortRetryStrategy;
22use crate::service_type::ServiceType;
23use std::sync::Arc;
24
25#[derive(Copy, Debug, Default, Clone, Eq, PartialEq)]
26pub enum ClusterState {
27    #[default]
28    Online,
29    Degraded,
30    Offline,
31}
32
33#[derive(Debug, Clone)]
34#[non_exhaustive]
35pub struct WaitUntilReadyOptions {
36    pub desired_state: Option<ClusterState>,
37    pub service_types: Option<Vec<ServiceType>>,
38    pub retry_strategy: Arc<dyn RetryStrategy>,
39
40    pub on_behalf_of: Option<OnBehalfOfInfo>,
41}
42
43impl Default for WaitUntilReadyOptions {
44    fn default() -> Self {
45        Self::new()
46    }
47}
48
49impl WaitUntilReadyOptions {
50    pub fn new() -> Self {
51        Self {
52            desired_state: None,
53            service_types: None,
54            retry_strategy: Arc::new(BestEffortRetryStrategy::default()),
55            on_behalf_of: None,
56        }
57    }
58
59    pub fn desired_state(mut self, state: ClusterState) -> Self {
60        self.desired_state = Some(state);
61        self
62    }
63
64    pub fn service_types(mut self, service_types: Vec<ServiceType>) -> Self {
65        self.service_types = Some(service_types);
66        self
67    }
68
69    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
70        self.retry_strategy = retry_strategy;
71        self
72    }
73
74    pub fn on_behalf_of(mut self, info: OnBehalfOfInfo) -> Self {
75        self.on_behalf_of = Some(info);
76        self
77    }
78}