feat(event-notifier): improve notification system initialization safety

- Add READY atomic flag to track full initialization status
- Implement initialize_safe and start_safe methods with mutex protection
- Add wait_until_ready function with configurable timeout
- Create initialize_and_start_with_ready_check helper method
- Replace sleep-based waiting with proper readiness checks
- Add safety checks before sending events
- Replace chrono with std::time for time handling
- Update error handling to provide clear initialization status

This change reduces race conditions in multi-threaded environments
and ensures events are only processed when the system is fully ready.
This commit is contained in:
houseme
2025-04-21 13:28:01 +08:00
parent bfc165abe0
commit 3b6397012b
12 changed files with 266 additions and 140 deletions
+1
View File
@@ -14,6 +14,7 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
let mut config = NotificationConfig {
store_path: "./events".to_string(),
channel_capacity: 100,
timeout: 50,
adapters: vec![AdapterConfig::Webhook(WebhookConfig {
endpoint: "http://localhost:8080/webhook".to_string(),
auth_token: Some("secret-token".to_string()),