(batch: Vec<NewEvent>, db_pool: DbPool)
| 34 | } |
| 35 | |
| 36 | async fn insert_batch(batch: Vec<NewEvent>, db_pool: DbPool) { |
| 37 | // Use `spawn_blocking` to move the blocking operation off the async executor |
| 38 | let result = task::spawn_blocking(move || { |
| 39 | // Now that `batch` is owned, it can be moved into the closure safely |
| 40 | let mut conn = db_pool |
| 41 | .get() |
| 42 | .expect("Failed to get DB connection from pool"); |
| 43 | |
| 44 | // Use `batch` directly as it is now owned by this closure |
| 45 | diesel::insert_into(crate::schema::events::table) |
| 46 | .values(&batch) |
| 47 | .execute(&mut conn) |
| 48 | }) |
| 49 | .await |
| 50 | .expect("Failed to execute block_in_place"); |
| 51 | |
| 52 | match result { |
| 53 | Ok(_) => println!("Batch inserted successfully."), |
| 54 | Err(e) => eprintln!("Failed to insert batch: {:?}", e), |
| 55 | } |
| 56 | } |
nothing calls this directly
no outgoing calls
no test coverage detected