feat: integrate event-notifier system with rustfs

- Rename package from rustfs-event-notifier to event-notifier for consistency
- Add shutdown hooks for event notification system in main process
- Handle graceful termination of notification services on server shutdown
- Implement initialization and configuration loading for event notification
- Fix environment variable configuration to properly parse adapter arrays
- Update example code to demonstrate proper configuration usage

This change ensures proper integration between rustfs and the event
notification system, with clean startup and shutdown sequences to prevent
resource leaks during application lifecycle.
This commit is contained in:
houseme
2025-04-22 20:49:39 +08:00
parent e4453adf82
commit 4f347a92c1
3 changed files with 33 additions and 5 deletions
+3 -3
View File
@@ -29,10 +29,10 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
})],
};
// load_config
// event_load_config
// loading configuration from environment variables
let _config = NotifierConfig::load_config(Some("./crates/event-notifier/examples/event.toml".to_string()));
tracing::info!("load_config config: {:?} \n", _config);
let _config = NotifierConfig::event_load_config(Some("./crates/event-notifier/examples/event.toml".to_string()));
tracing::info!("event_load_config config: {:?} \n", _config);
let system = Arc::new(tokio::sync::Mutex::new(NotifierSystem::new(config.clone()).await?));
let adapters = create_adapters(&config.adapters)?;
+2 -2
View File
@@ -102,9 +102,9 @@ impl NotifierConfig {
/// ```
/// use rustfs_event_notifier::NotifierConfig;
///
/// let config = NotifierConfig::load_config(None);
/// let config = NotifierConfig::event_load_config(None);
/// ```
pub fn load_config(config_dir: Option<String>) -> NotifierConfig {
pub fn event_load_config(config_dir: Option<String>) -> NotifierConfig {
let config_dir = if let Some(path) = config_dir {
// If a path is provided, check if it's empty
if path.is_empty() {
+28
View File
@@ -46,6 +46,7 @@ use hyper_util::{
use iam::init_iam_sys;
use license::init_license;
use protos::proto_gen::node_service::node_service_server::NodeServiceServer;
use rustfs_event_notifier::NotifierConfig;
use rustfs_obs::{init_obs, load_config, set_global_guard, InitLogStatus};
use rustls::ServerConfig;
use s3s::{host::MultiDomain, service::S3ServiceBuilder};
@@ -105,6 +106,23 @@ async fn main() -> Result<()> {
// Log initialization status
InitLogStatus::init_start_log(&config.observability).await?;
// Initialize event notifier
let notifier_config = opt.clone().event_config;
if notifier_config.is_some() {
info!("event_config is not empty");
tokio::spawn(async move {
let config = NotifierConfig::event_load_config(notifier_config);
let result = rustfs_event_notifier::initialize(config).await;
if let Err(e) = result {
error!("Failed to initialize event notifier: {}", e);
} else {
info!("Event notifier initialized successfully");
}
});
} else {
info!("event_config is empty");
}
// Run parameters
run(opt).await
}
@@ -448,6 +466,16 @@ async fn run(opt: config::Opt) -> Result<()> {
info!("Shutdown signal received in main thread");
// update the status to stopping first
state_manager.update(ServiceState::Stopping);
// Stop the notification system
if rustfs_event_notifier::is_ready() {
// stop event notifier
rustfs_event_notifier::shutdown().await.map_err(|err| {
error!("Failed to shut down the notification system: {}", err);
Error::from_string(err.to_string())
})?;
}
info!("Server is stopping...");
let _ = shutdown_tx.send(());
// Wait for the worker thread to complete the cleaning work