diff --git a/src/notifiers/base.rs b/src/notifiers/base.rs index fe9c14e..494051d 100644 --- a/src/notifiers/base.rs +++ b/src/notifiers/base.rs @@ -8,8 +8,8 @@ pub trait Notifier { async fn prepare(&mut self) -> RustusResult<()>; async fn send_message( &self, - message: String, - hook: Hook, + message: &str, + hook: &Hook, headers_map: &HeaderMap, ) -> RustusResult<()>; } diff --git a/src/notifiers/impls/amqp_notifier.rs b/src/notifiers/impls/amqp_notifier.rs index 3156ac3..ffe4856 100644 --- a/src/notifiers/impls/amqp_notifier.rs +++ b/src/notifiers/impls/amqp_notifier.rs @@ -153,12 +153,12 @@ impl Notifier for AMQPNotifier { #[tracing::instrument(skip(self, message, _header_map))] async fn send_message( &self, - message: String, - hook: Hook, + message: &str, + hook: &Hook, _header_map: &HeaderMap, ) -> RustusResult<()> { let chan = self.channel_pool.get().await?; - let queue = self.get_queue_name(&hook); + let queue = self.get_queue_name(hook); let routing_key = self.routing_key.as_ref().unwrap_or(&queue); let payload = if self.celery { format!("[[{message}], {{}}, {{}}]").as_bytes().to_vec() diff --git a/src/notifiers/impls/dir_notifier.rs b/src/notifiers/impls/dir_notifier.rs index 28cf908..7d97779 100644 --- a/src/notifiers/impls/dir_notifier.rs +++ b/src/notifiers/impls/dir_notifier.rs @@ -28,8 +28,8 @@ impl Notifier for DirNotifier { #[tracing::instrument(skip(self, message, _headers_map))] async fn send_message( &self, - message: String, - hook: Hook, + message: &str, + hook: &Hook, _headers_map: &HeaderMap, ) -> RustusResult<()> { let hook_path = self.dir.join(hook.to_string()); diff --git a/src/notifiers/impls/file_notifier.rs b/src/notifiers/impls/file_notifier.rs index 6c1e258..fe8dc46 100644 --- a/src/notifiers/impls/file_notifier.rs +++ b/src/notifiers/impls/file_notifier.rs @@ -27,8 +27,8 @@ impl Notifier for FileNotifier { #[tracing::instrument(err, skip(self, message, _headers_map), fields(exit_status = tracing::field::Empty))] async fn send_message( &self, - message: String, - hook: Hook, + message: &str, + hook: &Hook, _headers_map: &HeaderMap, ) -> RustusResult<()> { tracing::debug!("Running command: {}", self.command.as_str()); diff --git a/src/notifiers/impls/http_notifier.rs b/src/notifiers/impls/http_notifier.rs index 52fe18b..ec97835 100644 --- a/src/notifiers/impls/http_notifier.rs +++ b/src/notifiers/impls/http_notifier.rs @@ -37,12 +37,13 @@ impl Notifier for HttpNotifier { #[tracing::instrument(err, skip(self, message, header_map), fields(response_body = tracing::field::Empty))] async fn send_message( &self, - message: String, - hook: Hook, + message: &str, + hook: &Hook, header_map: &HeaderMap, ) -> RustusResult<()> { tracing::debug!("Starting HTTP Hook."); let idempotency_key = uuid::Uuid::new_v4().to_string(); + let body_bytes = bytes::Bytes::copy_from_slice(message.as_bytes()); let requests_vec = self.urls.iter().map(|url| { tracing::debug!("Preparing request for {}", url); let mut request = self @@ -57,7 +58,7 @@ impl Notifier for HttpNotifier { request = request.header(item.as_str(), value.as_bytes()); } } - request.body(message.clone()).send() + request.body(body_bytes.clone()).send() }); for response in requests_vec { let real_resp = response.await?; diff --git a/src/notifiers/manager.rs b/src/notifiers/manager.rs index 96ddadf..3b4e10e 100644 --- a/src/notifiers/manager.rs +++ b/src/notifiers/manager.rs @@ -87,16 +87,16 @@ impl NotificationManager { #[tracing::instrument(skip(self, hook, headers_map))] pub async fn notify_all( &self, - message: String, - hook: super::hooks::Hook, + message: &str, + hook: &super::hooks::Hook, headers_map: &HeaderMap, ) -> crate::errors::RustusResult<()> { - for notifier in &self.notifiers { + let collect = self.notifiers.iter().map(|notifier| { notifier - .send_message(message.clone(), hook, headers_map) + .send_message(message, hook, headers_map) .in_current_span() - .await?; - } + }); + futures::future::try_join_all(collect).await?; Ok(()) } } diff --git a/src/notifiers/mod.rs b/src/notifiers/mod.rs index af7b6c2..6f1bc74 100644 --- a/src/notifiers/mod.rs +++ b/src/notifiers/mod.rs @@ -27,8 +27,8 @@ impl base::Notifier for NotifierImpl { } async fn send_message( &self, - message: String, - hook: hooks::Hook, + message: &str, + hook: &hooks::Hook, headers_map: &HeaderMap, ) -> crate::errors::RustusResult<()> { match self { diff --git a/src/server/routes/create.rs b/src/server/routes/create.rs index e4800db..d752fd2 100644 --- a/src/server/routes/create.rs +++ b/src/server/routes/create.rs @@ -141,15 +141,20 @@ pub async fn handler( state .notificator .notify_all( - state.config.notification_config.hooks_format.format( - &uri, - &method, - &addr, - &headers, - state.config.behind_proxy, - &file_info, - ), - Hook::PreCreate, + state + .config + .notification_config + .hooks_format + .format( + &uri, + &method, + &addr, + &headers, + state.config.behind_proxy, + &file_info, + ) + .as_str(), + &Hook::PreCreate, &headers, ) .await?; @@ -200,7 +205,7 @@ pub async fn handler( async move { moved_state .notificator - .notify_all(message, post_hook, &headers) + .notify_all(&message, &post_hook, &headers) .await } .in_current_span(), diff --git a/src/server/routes/delete.rs b/src/server/routes/delete.rs index e43598d..6e9daef 100644 --- a/src/server/routes/delete.rs +++ b/src/server/routes/delete.rs @@ -45,15 +45,20 @@ pub async fn handler( state .notificator .notify_all( - state.config.notification_config.hooks_format.format( - &uri, - &method, - &addr, - &headers, - state.config.behind_proxy, - &file_info, - ), - Hook::PreTerminate, + state + .config + .notification_config + .hooks_format + .format( + &uri, + &method, + &addr, + &headers, + state.config.behind_proxy, + &file_info, + ) + .as_str(), + &Hook::PreTerminate, &headers, ) .await?; @@ -80,7 +85,7 @@ pub async fn handler( async move { state_cln .notificator - .notify_all(msg, Hook::PostTerminate, &headers) + .notify_all(&msg, &Hook::PostTerminate, &headers) .await } .in_current_span(), diff --git a/src/server/routes/upload.rs b/src/server/routes/upload.rs index 5a4cfff..a9e0e76 100644 --- a/src/server/routes/upload.rs +++ b/src/server/routes/upload.rs @@ -140,7 +140,7 @@ pub async fn handler( async move { state_clone .notificator - .notify_all(msg, hook, &headers_clone) + .notify_all(&msg, &hook, &headers_clone) .await .ok(); }