fix: use sequential when sub recipe task is 1. (#3573)

This commit is contained in:
Lifei Zhou
2025-07-22 13:23:48 +10:00
committed by GitHub
parent f0b4f74071
commit 9101bfece7
3 changed files with 24 additions and 13 deletions

View File

@@ -73,10 +73,15 @@ fn create_tasks_from_params(
}
fn create_task_execution_payload(tasks: &[Task], sub_recipe: &SubRecipe) -> Value {
let execution_mode = if tasks.len() == 1 || sub_recipe.sequential_when_repeated {
ExecutionMode::Sequential
} else {
ExecutionMode::Parallel
};
let task_ids: Vec<String> = tasks.iter().map(|task| task.id.clone()).collect();
json!({
"task_ids": task_ids,
"execution_mode": if sub_recipe.sequential_when_repeated { ExecutionMode::Sequential } else { ExecutionMode::Parallel },
"execution_mode": execution_mode,
})
}

View File

@@ -25,18 +25,7 @@ pub async fn execute_tasks(
)
.map_err(|e| format!("Failed to parse task_ids: {}", e))?;
let mut tasks = Vec::new();
for task_id in &task_ids {
match tasks_manager.get_task(task_id).await {
Some(task) => tasks.push(task),
None => {
return Err(format!(
"Task with ID '{}' not found in TasksManager",
task_id
))
}
}
}
let tasks = tasks_manager.get_tasks(&task_ids).await?;
let task_count = tasks.len();
match execution_mode {

View File

@@ -1,3 +1,4 @@
use anyhow::Result;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
@@ -33,6 +34,22 @@ impl TasksManager {
let tasks = self.tasks.read().await;
tasks.get(task_id).cloned()
}
pub async fn get_tasks(&self, task_ids: &[String]) -> Result<Vec<Task>, String> {
let mut tasks = Vec::new();
for task_id in task_ids {
match self.get_task(task_id).await {
Some(task) => tasks.push(task),
None => {
return Err(format!(
"Task with ID '{}' not found in TasksManager",
task_id
))
}
}
}
Ok(tasks)
}
}
#[cfg(test)]