(
state: AppState,
udid: String,
payload: BatchPayload,
)
| 458 | } |
| 459 | |
| 460 | async fn run_batch_steps( |
| 461 | state: AppState, |
| 462 | udid: String, |
| 463 | payload: BatchPayload, |
| 464 | ) -> Result<Value, AppError> { |
| 465 | if payload.steps.is_empty() { |
| 466 | return Err(AppError::bad_request( |
| 467 | "Batch action must include at least one step.", |
| 468 | )); |
| 469 | } |
| 470 | if payload.steps.len() > 256 { |
| 471 | return Err(AppError::bad_request( |
| 472 | "Batch action cannot contain more than 256 steps.", |
| 473 | )); |
| 474 | } |
| 475 | |
| 476 | let continue_on_error = payload.continue_on_error.unwrap_or(false); |
| 477 | let mut results = Vec::new(); |
| 478 | let mut failure_count = 0usize; |
| 479 | let mut should_warm_after_batch = false; |
| 480 | for (index, step) in payload.steps.into_iter().enumerate() { |
| 481 | let invalidates_ax_cache = batch_step_invalidates_ax_cache(&step); |
| 482 | let should_warm_ax = batch_step_should_warm_ax(&step); |
| 483 | if invalidates_ax_cache { |
| 484 | state.accessibility_cache.invalidate(&udid); |
| 485 | } |
| 486 | let started = Instant::now(); |
| 487 | let result = run_batch_step(state.clone(), udid.clone(), step).await; |
| 488 | let elapsed_ms = started.elapsed().as_millis() as u64; |
| 489 | match result { |
| 490 | Ok(value) => { |
| 491 | if should_warm_ax { |
| 492 | should_warm_after_batch = true; |
| 493 | } |
| 494 | results.push(json_value!({ |
| 495 | "index": index, |
| 496 | "ok": true, |
| 497 | "elapsedMs": elapsed_ms, |
| 498 | "result": value, |
| 499 | })); |
| 500 | } |
| 501 | Err(error) => { |
| 502 | failure_count += 1; |
| 503 | let message = error.to_string(); |
| 504 | results.push(json_value!({ |
| 505 | "index": index, |
| 506 | "ok": false, |
| 507 | "elapsedMs": elapsed_ms, |
| 508 | "error": message, |
| 509 | })); |
| 510 | if !continue_on_error { |
| 511 | return Err(AppError::bad_request(format!( |
| 512 | "Batch step {} failed: {}", |
| 513 | index + 1, |
| 514 | message |
| 515 | ))); |
| 516 | } |
| 517 | } |
no test coverage detected