lab-resource-manager 1.1.0

GPU and room resource management system with Google Calendar and Slack integration
Documentation
//! バックグラウンドタスク実行
//!
//! レスポンス追跡付きでバックグラウンドでタスクを実行するユーティリティ

use crate::interface::slack::slack_client::messages;
use slack_morphism::prelude::*;
use tokio_util::task::TaskTracker;

/// 操作をバックグラウンドで実行し、response URL経由で結果を送信
///
/// 結果はエフェメラルメッセージ(コマンド実行ユーザーのみ表示)として送信されます。
///
/// # 引数
/// * `task_tracker` - TaskTracker for managing background tasks
/// * `http_client` - HTTP client for sending follow-up messages
/// * `response_url` - Slack response URL to send the result to
/// * `operation` - Async operation to execute
///
/// # 戻り値
/// 処理開始を示す即時レスポンス
pub async fn execute_with_response<F, Fut>(
    task_tracker: &TaskTracker,
    http_client: reqwest::Client,
    response_url: SlackResponseUrl,
    operation: F,
) -> SlackCommandEventResponse
where
    F: FnOnce() -> Fut + Send + 'static,
    Fut: std::future::Future<Output = Result<String, String>> + Send + 'static,
{
    task_tracker.spawn(async move {
        let message = match operation().await {
            Ok(msg) => msg,
            Err(err) => err,
        };

        messages::send_ephemeral(&http_client, &response_url, message).await;
    });

    SlackCommandEventResponse::new(SlackMessageContent::new().with_text("⏳ 処理中...".to_string()))
}