standalone/
procedure.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16
17use common_meta::key::runtime_switch::RuntimeSwitchManager;
18use common_meta::kv_backend::KvBackendRef;
19use common_meta::state_store::KvStateStore;
20use common_procedure::ProcedureManagerRef;
21use common_procedure::local::{LocalManager, ManagerConfig};
22use common_procedure::options::ProcedureConfig;
23
24/// Builds the procedure manager.
25pub fn build_procedure_manager(
26    kv_backend: KvBackendRef,
27    procedure_config: ProcedureConfig,
28) -> ProcedureManagerRef {
29    let kv_state_store = Arc::new(KvStateStore::new(kv_backend.clone()));
30
31    let manager_config = ManagerConfig {
32        max_retry_times: procedure_config.max_retry_times,
33        retry_delay: procedure_config.retry_delay,
34        max_running_procedures: procedure_config.max_running_procedures,
35        ..Default::default()
36    };
37    let runtime_switch_manager = Arc::new(RuntimeSwitchManager::new(kv_backend));
38    Arc::new(LocalManager::new(
39        manager_config,
40        kv_state_store.clone(),
41        kv_state_store,
42        Some(runtime_switch_manager),
43        None,
44    ))
45}