improve code for notify

This commit is contained in:
houseme
2025-06-23 03:34:05 +08:00
parent c7af6587f5
commit 928453db62
30 changed files with 521 additions and 989 deletions
+15 -7
View File
@@ -1,7 +1,7 @@
use ecstore::config::{Config, KV, KVS};
use ecstore::config::{Config, ENABLE_KEY, ENABLE_ON, KV, KVS};
use rustfs_notify::arn::TargetID;
use rustfs_notify::factory::{
DEFAULT_TARGET, ENABLE, MQTT_BROKER, MQTT_PASSWORD, MQTT_QOS, MQTT_QUEUE_DIR, MQTT_QUEUE_LIMIT, MQTT_TOPIC, MQTT_USERNAME,
DEFAULT_TARGET, MQTT_BROKER, MQTT_PASSWORD, MQTT_QOS, MQTT_QUEUE_DIR, MQTT_QUEUE_LIMIT, MQTT_TOPIC, MQTT_USERNAME,
NOTIFY_MQTT_SUB_SYS, NOTIFY_WEBHOOK_SUB_SYS, WEBHOOK_AUTH_TOKEN, WEBHOOK_ENDPOINT, WEBHOOK_QUEUE_DIR, WEBHOOK_QUEUE_LIMIT,
};
use rustfs_notify::global::notification_system;
@@ -9,12 +9,20 @@ use rustfs_notify::store::DEFAULT_LIMIT;
use rustfs_notify::{init_logger, BucketNotificationConfig, Event, EventName, LogLevel, NotificationError};
use std::time::Duration;
use tracing::info;
use tracing_subscriber::util::SubscriberInitExt;
#[tokio::main]
async fn main() -> Result<(), NotificationError> {
init_logger(LogLevel::Debug);
let system = notification_system();
let system = match notification_system() {
Some(sys) => sys,
None => {
let config = Config::new();
notification_system::initialize(config).await?;
notification_system().expect("Failed to initialize notification system")
}
};
// --- Initial configuration (Webhook and MQTT) ---
let mut config = Config::new();
@@ -23,8 +31,8 @@ async fn main() -> Result<(), NotificationError> {
let webhook_kvs_vec = vec![
KV {
key: ENABLE.to_string(),
value: "on".to_string(),
key: ENABLE_KEY.to_string(),
value: ENABLE_ON.to_string(),
hidden_if_empty: false,
},
KV {
@@ -62,8 +70,8 @@ async fn main() -> Result<(), NotificationError> {
// MQTT target configuration
let mqtt_kvs_vec = vec![
KV {
key: ENABLE.to_string(),
value: "on".to_string(),
key: ENABLE_KEY.to_string(),
value: ENABLE_ON.to_string(),
hidden_if_empty: false,
},
KV {
+15 -7
View File
@@ -1,8 +1,8 @@
use ecstore::config::{Config, KV, KVS};
use ecstore::config::{Config, ENABLE_KEY, ENABLE_ON, KV, KVS};
// Using Global Accessories
use rustfs_notify::arn::TargetID;
use rustfs_notify::factory::{
DEFAULT_TARGET, ENABLE, MQTT_BROKER, MQTT_PASSWORD, MQTT_QOS, MQTT_QUEUE_DIR, MQTT_QUEUE_LIMIT, MQTT_TOPIC, MQTT_USERNAME,
DEFAULT_TARGET, MQTT_BROKER, MQTT_PASSWORD, MQTT_QOS, MQTT_QUEUE_DIR, MQTT_QUEUE_LIMIT, MQTT_TOPIC, MQTT_USERNAME,
NOTIFY_MQTT_SUB_SYS, NOTIFY_WEBHOOK_SUB_SYS, WEBHOOK_AUTH_TOKEN, WEBHOOK_ENDPOINT, WEBHOOK_QUEUE_DIR, WEBHOOK_QUEUE_LIMIT,
};
use rustfs_notify::global::notification_system;
@@ -10,13 +10,21 @@ use rustfs_notify::store::DEFAULT_LIMIT;
use rustfs_notify::{init_logger, BucketNotificationConfig, Event, EventName, LogLevel, NotificationError};
use std::time::Duration;
use tracing::info;
use tracing_subscriber::util::SubscriberInitExt;
#[tokio::main]
async fn main() -> Result<(), NotificationError> {
init_logger(LogLevel::Debug);
// Get global NotificationSystem instance
let system = notification_system();
let system = match notification_system() {
Some(sys) => sys,
None => {
let config = Config::new();
notification_system::initialize(config).await?;
notification_system().expect("Failed to initialize notification system")
}
};
// --- Initial configuration ---
let mut config = Config::new();
@@ -24,8 +32,8 @@ async fn main() -> Result<(), NotificationError> {
// Webhook target
let webhook_kvs_vec = vec![
KV {
key: ENABLE.to_string(),
value: "on".to_string(),
key: ENABLE_KEY.to_string(),
value: ENABLE_ON.to_string(),
hidden_if_empty: false,
},
KV {
@@ -72,8 +80,8 @@ async fn main() -> Result<(), NotificationError> {
let mqtt_kvs_vec = vec![
KV {
key: ENABLE.to_string(),
value: "on".to_string(),
key: ENABLE_KEY.to_string(),
value: ENABLE_ON.to_string(),
hidden_if_empty: false,
},
KV {