MCPcopy Create free account
hub / github.com/UdaraJay/Stats / insert_batch

Function insert_batch

src/utils/queue.rs:36–56  ·  view source on GitHub ↗
(batch: Vec<NewEvent>, db_pool: DbPool)

Source from the content-addressed store, hash-verified

34}
35
36async 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected