codex_memory/application/
application_service.rs

1use crate::application::DependencyContainer;
2use anyhow::Result;
3use std::sync::Arc;
4use tracing::info;
5
6/// Application service coordinates high-level business operations
7/// without containing business logic itself
8pub struct ApplicationService {
9    container: Arc<DependencyContainer>,
10}
11
12impl ApplicationService {
13    pub fn new(container: Arc<DependencyContainer>) -> Self {
14        Self { container }
15    }
16
17    /// Get system health status
18    pub async fn get_health_status(&self) -> Result<bool> {
19        self.container.health_check().await
20    }
21
22    /// Get system configuration summary
23    pub fn get_config_summary(&self) -> ConfigSummary {
24        ConfigSummary {
25            database_url: self.container.config.safe_database_url(),
26            embedding_provider: self.container.config.embedding.provider.clone(),
27            embedding_model: self.container.config.embedding.model.clone(),
28            http_port: self.container.config.http_port,
29            mcp_port: self.container.config.mcp_port,
30            tier_manager_enabled: self.container.config.tier_manager.enabled,
31            backup_enabled: self.container.config.backup.enabled,
32        }
33    }
34
35    /// Initialize all managed services
36    pub async fn initialize_services(&self) -> Result<()> {
37        info!("🔧 Initializing application services...");
38
39        // Initialize tier manager if enabled
40        if let Some(ref tier_manager) = self.container.tier_manager {
41            tier_manager.start().await?;
42            info!("✅ Tier management service started");
43        }
44
45        // Initialize backup manager if enabled
46        if let Some(ref backup_manager) = self.container.backup_manager {
47            backup_manager.initialize().await?;
48            info!("✅ Backup service initialized");
49        }
50
51        // Initialize harvester service
52        if let Some(ref _harvester) = self.container.harvester_service {
53            // TODO: Implement proper start method
54            // harvester.start().await?;
55            info!("✅ Silent harvester service started (placeholder)");
56        }
57
58        info!("🎉 All application services initialized successfully");
59        Ok(())
60    }
61
62    /// Shutdown all managed services gracefully
63    pub async fn shutdown_services(&self) -> Result<()> {
64        info!("🛑 Shutting down application services...");
65
66        // Shutdown in reverse order
67        if let Some(ref _harvester) = self.container.harvester_service {
68            // TODO: Implement proper stop method
69            // harvester.stop().await?;
70            info!("✅ Silent harvester service stopped (placeholder)");
71        }
72
73        if let Some(ref tier_manager) = self.container.tier_manager {
74            tier_manager.stop().await;
75            info!("✅ Tier management service stopped");
76        }
77
78        info!("🎉 All application services shutdown gracefully");
79        Ok(())
80    }
81}
82
83#[derive(Debug, Clone)]
84pub struct ConfigSummary {
85    pub database_url: String,
86    pub embedding_provider: String,
87    pub embedding_model: String,
88    pub http_port: u16,
89    pub mcp_port: Option<u16>,
90    pub tier_manager_enabled: bool,
91    pub backup_enabled: bool,
92}