From 7251cccd0310b17575786f695a9848600d6ebbaa Mon Sep 17 00:00:00 2001 From: Mubelotix Date: Mon, 4 Aug 2025 17:13:05 +0200 Subject: [PATCH] Make notify_webhooks execute in its own thread --- crates/index-scheduler/src/lib.rs | 10 ++-------- crates/index-scheduler/src/scheduler/mod.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/index-scheduler/src/lib.rs b/crates/index-scheduler/src/lib.rs index 84cb0f752..9af74a3e5 100644 --- a/crates/index-scheduler/src/lib.rs +++ b/crates/index-scheduler/src/lib.rs @@ -766,14 +766,8 @@ impl IndexScheduler { Ok(()) } - /// Once the tasks changes have been committed we must send all the tasks that were updated to our webhook if there is one. - fn notify_webhook(&self, updated: &RoaringBitmap) -> Result<()> { - let webhooks = self.cached_webhooks.read().unwrap_or_else(|poisoned| poisoned.into_inner()); - if webhooks.webhooks.is_empty() { - return Ok(()); - } - let webhooks = Webhooks::clone(&*webhooks); - + /// Once the tasks changes have been committed we must send all the tasks that were updated to our webhooks + fn notify_webhooks(&self, webhooks: Webhooks, updated: &RoaringBitmap) -> Result<()> { struct TaskReader<'a, 'b> { rtxn: &'a RoTxn<'a>, index_scheduler: &'a IndexScheduler, diff --git a/crates/index-scheduler/src/scheduler/mod.rs b/crates/index-scheduler/src/scheduler/mod.rs index 5ac591143..b5acf7582 100644 --- a/crates/index-scheduler/src/scheduler/mod.rs +++ b/crates/index-scheduler/src/scheduler/mod.rs @@ -26,6 +26,7 @@ use meilisearch_types::error::ResponseError; use meilisearch_types::heed::{Env, WithoutTls}; use meilisearch_types::milli; use meilisearch_types::tasks::Status; +use meilisearch_types::webhooks::Webhooks; use process_batch::ProcessBatchInfo; use rayon::current_num_threads; use rayon::iter::{IntoParallelIterator, ParallelIterator}; @@ -446,8 +447,17 @@ impl IndexScheduler { Ok(()) })?; - // We shouldn't crash the tick function if we can't send data to the webhook. - let _ = self.notify_webhook(&ids); + // We shouldn't crash the tick function if we can't send data to the webhooks + let webhooks = self.cached_webhooks.read().unwrap_or_else(|p| p.into_inner()); + if !webhooks.webhooks.is_empty() { + let webhooks = Webhooks::clone(&*webhooks); + let cloned_index_scheduler = self.private_clone(); + std::thread::spawn(move || { + if let Err(e) = cloned_index_scheduler.notify_webhooks(webhooks, &ids) { + tracing::error!("Failure to notify webhooks: {e}"); + } + }); + } #[cfg(test)] self.breakpoint(crate::test_utils::Breakpoint::AfterProcessing);