Feature/event: Optimize and Enhance Notify Crate Functionality (#512)

* improve code for notify

* fix

* cargo fmt

* improve code and create `DEFAULT_DELIMITER`

* fix

* fix

* improve code for notify

* fmt

* Update crates/notify/src/registry.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update crates/notify/src/factory.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix cllipy

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
houseme
2025-06-26 12:24:00 +08:00
committed by GitHub
parent 61e600b9ba
commit 831cb0b6d9
31 changed files with 342 additions and 151 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
use crate::store::{Key, STORE_EXTENSION};
use crate::store::Key;
use crate::target::ChannelTargetType;
use crate::{
StoreError, Target,
@@ -10,6 +10,7 @@ use crate::{
use async_trait::async_trait;
use rumqttc::{AsyncClient, EventLoop, MqttOptions, Outgoing, Packet, QoS};
use rumqttc::{ConnectionError, mqttbytes::Error as MqttBytesError};
use rustfs_config::notify::STORE_EXTENSION;
use std::sync::Arc;
use std::{
path::PathBuf,
+7 -7
View File
@@ -1,4 +1,3 @@
use crate::store::STORE_EXTENSION;
use crate::target::ChannelTargetType;
use crate::{
StoreError, Target,
@@ -9,6 +8,7 @@ use crate::{
};
use async_trait::async_trait;
use reqwest::{Client, StatusCode, Url};
use rustfs_config::notify::STORE_EXTENSION;
use std::{
path::PathBuf,
sync::{
@@ -41,8 +41,8 @@ pub struct WebhookArgs {
pub client_key: String,
}
// WebhookArgs 的验证方法
impl WebhookArgs {
/// WebhookArgs verification method
pub fn validate(&self) -> Result<(), TargetError> {
if !self.enable {
return Ok(());
@@ -134,7 +134,7 @@ impl WebhookTarget {
target_id.name,
target_id.id
));
let store = super::super::store::QueueStore::<Event>::new(queue_dir, args.queue_limit, STORE_EXTENSION);
let store = crate::store::QueueStore::<Event>::new(queue_dir, args.queue_limit, STORE_EXTENSION);
if let Err(e) = store.open() {
error!("Failed to open store for Webhook target {}: {}", target_id.id, e);
@@ -172,9 +172,9 @@ impl WebhookTarget {
}
async fn init(&self) -> Result<(), TargetError> {
// 使用 CAS 操作确保线程安全初始化
// Use CAS operations to ensure thread-safe initialization
if !self.initialized.load(Ordering::SeqCst) {
// 检查连接
// Check the connection
match self.is_active().await {
Ok(true) => {
info!("Webhook target {} is active", self.id);
@@ -209,12 +209,12 @@ impl WebhookTarget {
let data =
serde_json::to_vec(&log).map_err(|e| TargetError::Serialization(format!("Failed to serialize event: {}", e)))?;
// Vec<u8> 转换为 String
// Vec<u8> Convert to String
let data_string = String::from_utf8(data.clone())
.map_err(|e| TargetError::Encoding(format!("Failed to convert event data to UTF-8: {}", e)))?;
debug!("Sending event to webhook target: {}, event log: {}", self.id, data_string);
// 构建请求
// build request
let mut req_builder = self
.http_client
.post(self.args.endpoint.as_str())