# `SiteMaps.Oban.Worker`
[🔗](https://github.com/marcosgz/site_maps_ex/blob/v0.1.0/lib/site_maps/oban/worker.ex#L2)

Oban worker that runs `SiteMaps.generate/2`. Compiled only when Oban is available.

    MyApp.Sitemaps
    |> SiteMaps.Oban.Worker.new_job(context: %{site: "acme"}, only: [posts: [year: 2026, month: 3]])
    |> Oban.insert()

Jobs run on the `:sitemaps` queue. Process arguments, including declared defaults, are resolved
when the job is built, so a retried job regenerates the same shards. Inserting a job is a no-op
while an identical run (same module, context and resolved processes) is available, scheduled,
executing or retryable; once that job completes, is discarded or cancelled, the same run can be
enqueued again. Different runs of the same context, e.g. a full run and a partial one, are
separate jobs and may run at the same time; to serialize the runs of a site, give each site its
own queue with `limit: 1` (pass `queue:` to `new_job/2`) or run the `:sitemaps` queue with
`limit: 1`.

The context must be JSON serializable and arrives at the callbacks as the decoded, string-keyed
map. A sitemap module that implements `c:SiteMaps.load_context/1` receives that map to build its
own context (e.g. to load a `%Site{}` from its slug).

# `new_job`

```elixir
@spec new_job(module(), keyword()) :: Ecto.Changeset.t()
```

Builds the job changeset for `module`.

## Options

  * `:context` - JSON serializable map (default `%{}`)
  * `:only` - processes to run, e.g. `[:static, posts: [year: 2026, month: 3]]`. By default
    every declared process runs. Missing arguments are filled with the declared defaults now,
    so a retried job regenerates the same shards.
  * `:prune` - see `SiteMaps.generate/2` (default `false`)

Other options (such as `queue:` or `scheduled_at:`) are given to the worker's `new/2`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
