Skip to main content

torrust_tracker_deployer_lib/bootstrap/
sdk.rs

1//! Bootstrap helpers for the SDK package
2//!
3//! This module creates the default infrastructure dependencies that the SDK
4//! (`torrust-tracker-deployer-sdk`) needs, without requiring the SDK to import
5//! from the infrastructure layer directly.
6//!
7//! The bootstrap layer is explicitly allowed to cross-cut all DDD layers for
8//! dependency injection, which is why infrastructure types are imported here
9//! rather than inside the SDK package.
10
11use std::sync::Arc;
12use std::time::Duration;
13
14use crate::application::traits::RepositoryProvider;
15use crate::infrastructure::persistence::file_repository_factory::FileRepositoryFactory;
16use crate::shared::SystemClock;
17use torrust_tracker_deployer_types::Clock;
18
19/// The default file-lock timeout used by the SDK when no custom value is provided.
20pub const DEFAULT_SDK_LOCK_TIMEOUT: Duration = Duration::from_secs(30);
21
22/// Create the default repository provider backed by the file-based `FileRepositoryFactory`.
23///
24/// The SDK builder calls this to construct its provider without importing any
25/// infrastructure type directly.
26///
27/// # Arguments
28///
29/// * `lock_timeout` — How long the repository factory waits to acquire a file lock.
30#[must_use]
31pub fn default_repository_provider(lock_timeout: Duration) -> Arc<dyn RepositoryProvider> {
32    Arc::new(FileRepositoryFactory::new(lock_timeout))
33}
34
35/// Create the default system clock.
36///
37/// Returns a `SystemClock` wrapped in the `Clock` trait object so the SDK
38/// builder does not need to import `SystemClock` from `crate::shared`.
39#[must_use]
40pub fn default_clock() -> Arc<dyn Clock> {
41    Arc::new(SystemClock)
42}