fix(backend): remove nested tokio block_on in cancel commands

This commit is contained in:
thibaud-lclr 2026-04-21 11:34:53 +02:00
parent b6e31f9312
commit aea8d0b73b
2 changed files with 10 additions and 6 deletions

View file

@ -3,7 +3,6 @@ use crate::models::ticket::ProcessedTicket;
use crate::models::worktree::Worktree;
use crate::AppState;
use serde::Serialize;
use tauri::async_runtime;
use tauri::State;
#[derive(Debug, Clone, Serialize)]
@ -58,7 +57,10 @@ pub fn retry_ticket(state: State<'_, AppState>, ticket_id: String) -> Result<(),
}
#[tauri::command]
pub fn cancel_ticket(state: State<'_, AppState>, ticket_id: String) -> Result<(), AppError> {
pub async fn cancel_ticket(
state: State<'_, AppState>,
ticket_id: String,
) -> Result<(), AppError> {
{
let conn = state.db.lock().map_err(|e| AppError::from(e.to_string()))?;
let ticket = ProcessedTicket::get_by_id(&conn, &ticket_id)?;
@ -71,7 +73,7 @@ pub fn cancel_ticket(state: State<'_, AppState>, ticket_id: String) -> Result<()
}
}
async_runtime::block_on(state.process_registry.cancel_ticket(&ticket_id));
state.process_registry.cancel_ticket(&ticket_id).await;
let conn = state.db.lock().map_err(|e| AppError::from(e.to_string()))?;
let ticket = ProcessedTicket::get_by_id(&conn, &ticket_id)?;

View file

@ -4,7 +4,6 @@ use crate::models::agent_task::AgentTask;
use crate::models::module::{ProjectModule, MODULE_AGENT_TASK_RUNNER};
use crate::models::project::Project;
use crate::AppState;
use tauri::async_runtime;
use tauri::State;
#[tauri::command]
@ -87,7 +86,10 @@ pub fn retry_agent_task(state: State<'_, AppState>, task_id: String) -> Result<(
}
#[tauri::command]
pub fn cancel_agent_task(state: State<'_, AppState>, task_id: String) -> Result<(), AppError> {
pub async fn cancel_agent_task(
state: State<'_, AppState>,
task_id: String,
) -> Result<(), AppError> {
{
let db = state
.db
@ -103,7 +105,7 @@ pub fn cancel_agent_task(state: State<'_, AppState>, task_id: String) -> Result<
}
}
async_runtime::block_on(state.process_registry.cancel_task(&task_id));
state.process_registry.cancel_task(&task_id).await;
let db = state
.db