# Batches

Batches group jobs together and run callbacks after processing.

```elixir
defmodule MyApp.EmailWorker do
  use Oban.Pro.Worker

  @behaviour Oban.Pro.Batch

  @impl Oban.Pro.Worker
  def process(%{args: %{"email" => email}}) do
    MyApp.Mailer.deliver(email)
  end

  @impl Oban.Pro.Batch
  def batch_completed(job) do
    Logger.info("Batch #{job.meta["batch_id"]} completed")
    :ok
  end
end
```

## Creating batches

```elixir
alias Oban.Pro.Batch

emails
|> Enum.map(&EmailWorker.new(%{email: &1}))
|> Batch.new()
|> Oban.insert_all()
```

## Callbacks

| Callback            | Triggered when                              |
|---------------------|---------------------------------------------|
| `batch_attempted/1` | All jobs executed at least once             |
| `batch_completed/1` | All jobs completed successfully             |
| `batch_exhausted/1` | All jobs completed, cancelled, or discarded |
| `batch_cancelled/1` | First job is cancelled                      |
| `batch_discarded/1` | First job is discarded                      |
