Oban.Pro.Archive (Oban Pro v1.8.0-rc.1)

A queryable for reading archived jobs from the oban_jobs_archive table.

Rules with archive: true copy matched jobs into oban_jobs_archive before they're deleted from oban_jobs (see Oban.Pro.Pruner). Because the archive mirrors the jobs table, rows load as ordinary Oban.Job structs and this module can be used wherever an Ecto queryable is expected.

Filtering with query/1

Like Oban.Job.query/1, query/1 builds a query from a keyword list of filters. It pairs with Oban.all_jobs/2, so archived jobs load through the configured instance and prefix:

[worker: MyApp.AuditWorker, state: "completed"]
|> Oban.Pro.Archive.query()
|> Oban.all_jobs()

Querying Directly

The module is also a plain queryable, so pass it straight to your repo or compose it with Ecto.Query:

# Fetch a single archived job by id
Repo.get(Oban.Pro.Archive, 123)

# Every archived job
Repo.all(Oban.Pro.Archive)

# Compose like any other schema; results are `Oban.Job` structs
import Ecto.Query

Oban.Pro.Archive
|> where([j], j.worker == "MyApp.AuditWorker")
|> order_by([j], desc: j.id)
|> Repo.all()

For a non-default prefix, pass it through as usual:

Repo.all(Oban.Pro.Archive, prefix: "private")

Summary

Functions

Build a query for archived jobs from a keyword list of filters.

Functions

query(filters)

@spec query([{atom(), term()}]) :: Ecto.Query.t()

Build a query for archived jobs from a keyword list of filters.

Mirrors Oban.Job.query/1, applying the same field coercion and matching, but reading from the archive table.

Examples

Filter archived jobs by worker and state:

query = Oban.Pro.Archive.query(worker: MyApp.AuditWorker, state: "completed")