use std::future::Future;
use tracing::{error, info};

pub fn spawn_with_error_handling<F>(task_name: &str, future: F)
where
    F: Future<Output = crate::error::Result<()>> + Send + 'static,
{
    let task_name = task_name.to_string();
    tokio::spawn(async move {
        match future.await {
            Ok(()) => {
                info!("Background task '{}' completed successfully", task_name);
            }
            Err(e) => {
                error!("Background task '{}' failed: {:?}", task_name, e);
            }
        }
    });
}

