oban-bg/oban

Replace job state on conflict

Closed this issue · 1 comments

sezaru commented

Is your feature request related to a problem? Please describe.

Oban allows you to set which fields to change when there is a conflict and the job is in the discarded state but it doesn't allow to also change the job status, meaning that, for a discarded job, you can replace the fields with the new job on conflict, but the job will remain in the discarded state instead of changing it to something like scheduled.

Describe the Solution You'd Like

To be honest, I was expecting that a discarded job that had a conflict would just go back to the scheduled state after the conflict fields are replaced.

At least, I would expect an option like retry_on_conflict or something like that to allow this scenario.

Jobs with a discarded or cancelled state aren't considered for uniqueness, insertion will always work without a conflict. It's best to be highly targeted in which states/fields you'll update anyhow.

If you've explicitly set unique states to include discarded and you want to retry on conflict, you'll need to write a little wrapper to handle it:

changeset = Worker.new(some_args)

with {:ok, %{conflict?: true, state: "discarded"}} <- Oban.insert(changeset) do
  some_args
  |> Worker.new(unique: [states: [:available]])
  |> Oban.insert()
end