Previous commit (3c988a5f) switched oban_pro to the licensed hex repo at deploy time. Reverting that — keep all three Pro packages vendored so prod image builds don't depend on oban.pro reachability or auth on every CI run. oban_pro 1.7.0 dropped into vendor/oban_pro via `mix hex.package fetch oban_pro 1.7.0 --repo=oban --unpack`. mix.exs goes back to `path: "vendor/oban_pro"` (matching oban_met / oban_web, which were already vendored — and stay vendored since the licensed repo only has older versions of those: 0.1.11 / 2.10.6 vs the 1.1.0 / 2.12.1 we vendor). Schema migration from3c988a5fstays — 1.7.0 tables/indexes are already applied. No code changes.
43 lines
1 KiB
Markdown
43 lines
1 KiB
Markdown
# 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 |
|