Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed notification signature to pass all by references. #148

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/notifiers/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;
}
6 changes: 3 additions & 3 deletions src/notifiers/impls/amqp_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/notifiers/impls/dir_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/notifiers/impls/file_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 4 additions & 3 deletions src/notifiers/impls/http_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?;
Expand Down
12 changes: 6 additions & 6 deletions src/notifiers/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
4 changes: 2 additions & 2 deletions src/notifiers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 15 additions & 10 deletions src/server/routes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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(),
Expand Down
25 changes: 15 additions & 10 deletions src/server/routes/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading