Skip to content

Commit

Permalink
refactor(publisher): ensure blocking telemetry tasks executes in a de…
Browse files Browse the repository at this point in the history
…dicated thread for blocking tasks
  • Loading branch information
Jurshsmith committed Nov 11, 2024
1 parent 4a44f35 commit 54f7844
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 1 addition & 3 deletions crates/fuel-streams-publisher/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ impl Telemetry {
tracing::info!("Elastic logger pinged successfully!");
};

self.runtime.start();

self.runtime.spawn(async move {
self.runtime.start(move || {
system.write().refresh();
});

Expand Down
7 changes: 6 additions & 1 deletion crates/fuel-streams-publisher/src/telemetry/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ impl Runtime {
queue.push_back(Box::pin(task));
}

pub fn start(&self) {
pub fn start<F>(&self, blocking_task_executor: F)
where
F: FnOnce() + Send + 'static + Clone,
{
let interval = self.interval;
let task_queue = Arc::clone(&self.task_queue);

Expand All @@ -51,6 +54,8 @@ impl Runtime {
// Wait for the interval
ticker.tick().await;

tokio::task::spawn_blocking(blocking_task_executor.clone());

// Lock the queue, drain tasks, and run them sequentially
let tasks: Vec<_> = {
let mut queue = task_queue.lock().unwrap();
Expand Down

0 comments on commit 54f7844

Please sign in to comment.