pub struct ExecutionContext { /* private fields */ }Expand description
§Design Consideration: Shared State Access
Currently, there is no shared mutable state in the system that requires Arc<Mutex<T>>
patterns. However, if shared state is needed in the future, it can be added to the
Container and accessed through standard Rust concurrency patterns:
§Examples
use std::sync::Arc;
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
let container = Arc::new(Container::new(VerbosityLevel::Normal, Path::new(".")));
let context = ExecutionContext::new(container, global_args);
// Access user output service
let user_output = context.user_output();
user_output.lock().borrow_mut().success("Operation completed");Implementations§
Source§impl ExecutionContext
impl ExecutionContext
Sourcepub fn new(container: Arc<Container>, global_args: GlobalArgs) -> Self
pub fn new(container: Arc<Container>, global_args: GlobalArgs) -> Self
Create a new execution context from a container
§Arguments
container- Application service container with initialized servicesglobal_args- Global CLI arguments (logging config, output format, etc.)
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use torrust_tracker_deployer_lib::presentation::cli::input::cli::args::GlobalArgs;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput};
use torrust_tracker_deployer_lib::presentation::cli::input::cli::OutputFormat;
use std::sync::Arc;
use std::path::PathBuf;
let container = Container::new(VerbosityLevel::Normal, &PathBuf::from("."));
let global_args = GlobalArgs {
log_file_format: LogFormat::Compact,
log_stderr_format: LogFormat::Pretty,
log_output: LogOutput::FileOnly,
log_dir: PathBuf::from("./data/logs"),
working_dir: PathBuf::from("."),
output_format: OutputFormat::Text,
verbosity: 0,
};
let context = ExecutionContext::new(Arc::new(container), global_args);Sourcepub fn container(&self) -> &Arc<Container> ⓘ
pub fn container(&self) -> &Arc<Container> ⓘ
Get reference to the underlying container
Provides access to the raw container for cases where direct access to container methods is needed.
§Examples
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use std::sync::Arc;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let context = ExecutionContext::new(Arc::new(container), global_args);
let container_ref = context.container();
// Use container_ref as neededSourcepub fn user_output(&self) -> Arc<ReentrantMutex<RefCell<UserOutput>>> ⓘ
pub fn user_output(&self) -> Arc<ReentrantMutex<RefCell<UserOutput>>> ⓘ
Get shared reference to user output service
Returns the user output service for displaying messages, progress,
and results to users. The service is wrapped in Arc<Mutex<T>> for
thread-safe shared access.
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use std::sync::Arc;
use std::path::Path;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let context = ExecutionContext::new(Arc::new(container), global_args);
let user_output = context.user_output();
user_output.lock().borrow_mut().success("Operation completed");Sourcepub fn file_repository_factory(&self) -> Arc<FileRepositoryFactory> ⓘ
pub fn file_repository_factory(&self) -> Arc<FileRepositoryFactory> ⓘ
Get shared reference to repository factory service
Returns the repository factory service for creating environment
repositories. The service is wrapped in Arc<T> for shared access.
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use std::sync::Arc;
use std::path::Path;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let context = ExecutionContext::new(Arc::new(container), global_args);
let file_repository_factory = context.file_repository_factory();
// Use file_repository_factory to create repositoriesSourcepub fn repository(&self) -> Arc<dyn EnvironmentRepository + Send + Sync> ⓘ
pub fn repository(&self) -> Arc<dyn EnvironmentRepository + Send + Sync> ⓘ
Get shared reference to environment repository
Returns the environment repository for persistence operations.
The repository is wrapped in Arc<dyn EnvironmentRepository> for shared access.
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use std::sync::Arc;
use std::path::Path;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let context = ExecutionContext::new(Arc::new(container), global_args);
let repository = context.repository();
// Use repository for environment persistenceSourcepub fn clock(&self) -> Arc<dyn Clock> ⓘ
pub fn clock(&self) -> Arc<dyn Clock> ⓘ
Get shared reference to clock service
Returns the clock service for time-related operations.
The service is wrapped in Arc<dyn Clock> for shared access.
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use std::sync::Arc;
use std::path::Path;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let context = ExecutionContext::new(Arc::new(container), global_args);
let clock = context.clock();
// Use clock for time operationsSourcepub fn output_format(&self) -> OutputFormat
pub fn output_format(&self) -> OutputFormat
Get the output format from global CLI arguments
Returns the user-specified output format (Text or Json) for command results. This allows controllers to format their output appropriately based on user preference.
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use torrust_tracker_deployer_lib::presentation::cli::input::cli::args::GlobalArgs;
use torrust_tracker_deployer_lib::presentation::cli::input::cli::OutputFormat;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput};
use std::sync::Arc;
use std::path::PathBuf;
let container = Container::new(VerbosityLevel::Normal, &PathBuf::from("."));
let global_args = GlobalArgs {
log_file_format: LogFormat::Compact,
log_stderr_format: LogFormat::Pretty,
log_output: LogOutput::FileOnly,
log_dir: PathBuf::from("./data/logs"),
working_dir: PathBuf::from("."),
output_format: OutputFormat::Json,
verbosity: 0,
};
let context = ExecutionContext::new(Arc::new(container), global_args);
let format = context.output_format();
match format {
OutputFormat::Text => println!("Human-readable text"),
OutputFormat::Json => println!("{{\"result\": \"json\"}}"),
}Sourcepub fn working_dir(&self) -> &Path
pub fn working_dir(&self) -> &Path
Get the working directory from global CLI arguments
Returns the working directory path specified by the user (or default “.”). This is where environment data will be stored (data/ and build/ subdirectories).
§Examples
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use torrust_tracker_deployer_lib::presentation::cli::input::cli::args::GlobalArgs;
use torrust_tracker_deployer_lib::presentation::cli::input::cli::OutputFormat;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput};
use std::sync::Arc;
use std::path::PathBuf;
let container = Container::new(VerbosityLevel::Normal, &PathBuf::from("."));
let global_args = GlobalArgs {
log_file_format: LogFormat::Compact,
log_stderr_format: LogFormat::Pretty,
log_output: LogOutput::FileOnly,
log_dir: PathBuf::from("./data/logs"),
working_dir: PathBuf::from("/tmp/test-workspace"),
output_format: OutputFormat::Text,
verbosity: 0,
};
let context = ExecutionContext::new(Arc::new(container), global_args);
let working_dir = context.working_dir();
println!("Working directory: {}", working_dir.display());Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ExecutionContext
impl !UnwindSafe for ExecutionContext
impl Freeze for ExecutionContext
impl Send for ExecutionContext
impl Sync for ExecutionContext
impl Unpin for ExecutionContext
impl UnsafeUnpin for ExecutionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request