Skip to main content

BatchItemHandler

Trait BatchItemHandler 

Source
pub trait BatchItemHandler<D>:
    Send
    + Sync
    + 'static
where D: Clone + Send + Sync + Serialize,
{ // Required method fn process( &self, data: &D, resource_key: &str, operation: &str, ) -> impl Future<Output = Result<ItemResult>> + Send; // Provided method fn should_skip(&self, _data: &D, _operation: &str) -> bool { ... } }
Expand description

Trait for processing individual items in a batch.

Implement this for your application to define:

  • How to process each item (process)
  • Whether an item should be skipped (should_skip)

§Type Parameter

D is the per-item data type (e.g. a file path, image reference, document ID).

§Example

use ai_batch_queue::*;

struct MyProcessor;

impl BatchItemHandler<String> for MyProcessor {
    async fn process(
        &self,
        data: &String,
        resource_key: &str,
        operation: &str,
    ) -> anyhow::Result<ItemResult> {
        println!("Processing {} with {}", data, resource_key);
        Ok(ItemResult::success())
    }

    fn should_skip(&self, data: &String, operation: &str) -> bool {
        false // never skip
    }
}

Required Methods§

Source

fn process( &self, data: &D, resource_key: &str, operation: &str, ) -> impl Future<Output = Result<ItemResult>> + Send

Process a single item.

§Arguments
  • data — the item’s user-defined data payload
  • resource_key — the resource this batch uses (e.g. model name)
  • operation — the operation label (e.g. “tag”, “caption”)

Provided Methods§

Source

fn should_skip(&self, _data: &D, _operation: &str) -> bool

Check if this item should be skipped when the overwrite policy is Skip.

Return true to skip (item already has results). Default implementation never skips.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§