Skip to main content

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, DEFAULT_RETRY_STRATEGY};
21use crate::service_type::ServiceType;
22use std::sync::Arc;
23
24#[derive(Copy, Debug, Default, Clone, Eq, PartialEq)]
25pub enum ClusterState {
26    #[default]
27    Online,
28    Degraded,
29    Offline,
30}
31
32#[derive(Debug, Clone)]
33#[non_exhaustive]
34pub struct WaitUntilReadyOptions {
35    pub desired_state: Option<ClusterState>,
36    pub service_types: Option<Vec<ServiceType>>,
37    pub retry_strategy: Arc<dyn RetryStrategy>,
38
39    pub on_behalf_of: Option<OnBehalfOfInfo>,
40}
41
42impl Default for WaitUntilReadyOptions {
43    fn default() -> Self {
44        Self::new()
45    }
46}
47
48impl WaitUntilReadyOptions {
49    pub fn new() -> Self {
50        Self {
51            desired_state: None,
52            service_types: None,
53            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
54            on_behalf_of: None,
55        }
56    }
57
58    pub fn desired_state(mut self, state: ClusterState) -> Self {
59        self.desired_state = Some(state);
60        self
61    }
62
63    pub fn service_types(mut self, service_types: Vec<ServiceType>) -> Self {
64        self.service_types = Some(service_types);
65        self
66    }
67
68    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
69        self.retry_strategy = retry_strategy;
70        self
71    }
72
73    pub fn on_behalf_of(mut self, info: OnBehalfOfInfo) -> Self {
74        self.on_behalf_of = Some(info);
75        self
76    }
77}