Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/oban/engines/basic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ defmodule Oban.Engines.Basic do

@impl Engine
def insert_job(%Config{} = conf, %Changeset{} = changeset, opts) do
fun = fn -> insert_unique(conf, changeset, opts) end
if Repo.in_transaction?(conf) do
insert_unique(conf, changeset, opts)
else
fun = fn -> insert_unique(conf, changeset, opts) end

with {:ok, result} <- Repo.transaction(conf, fun), do: result
with {:ok, result} <- Repo.transaction(conf, fun), do: result
end
end

@impl Engine
Expand Down
10 changes: 10 additions & 0 deletions test/oban/engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@
assert job_1.id != job_2.id
assert job_1.id == job_3.id
end

@tag skip: @engine != Basic
@tag :unboxed
@tag oban_opts: [repo: UnboxedRepo]
test "propagating db errors raised when inserting within a multi", %{name: name} do
changeset = Worker.new(%{ref: 1}) |> Ecto.Changeset.put_change(:state, "bogus")

Check warning on line 320 in test/oban/engine_test.exs

View workflow job for this annotation

GitHub Actions / ci (1.19, 28.1, 9.1, 18.3-alpine, gossip, lint)

Pipe chain should start with a raw value.

Check warning on line 320 in test/oban/engine_test.exs

View workflow job for this annotation

GitHub Actions / ci (1.19, 28.1, 9.1, 18.3-alpine, gossip, lint)

Use a function call when a pipeline is only one function long.
multi = Oban.insert(name, Multi.new(), :job, changeset)

assert_raise Postgrex.Error, fn -> UnboxedRepo.transaction(multi) end
end
end

describe "insert!/2" do
Expand Down
Loading