Skip to content
Open
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
14 changes: 6 additions & 8 deletions lib/projections/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ defmodule Commanded.Projections.Ecto do
schema_prefix =
opts[:schema_prefix] || Application.get_env(:commanded_ecto_projections, :schema_prefix)

timeout = opts[:timeout] || :infinity
handler_opts = Keyword.drop(opts, [:repo, :schema_prefix, :timeout])

quote location: :keep do
@behaviour Commanded.Projections.Ecto

@opts unquote(opts)
@repo @opts[:repo] || Application.compile_env(:commanded_ecto_projections, :repo) ||
@repo unquote(opts[:repo]) || Application.compile_env(:commanded_ecto_projections, :repo) ||
raise("Commanded Ecto projections expects :repo to be configured in environment")
@timeout @opts[:timeout] || :infinity

# Pass through any other configuration to the event handler
@handler_opts Keyword.drop(@opts, [:repo, :schema_prefix, :timeout])

unquote(__include_schema_prefix__(schema_prefix))
unquote(__include_projection_version_schema__())

use Ecto.Schema
use Commanded.Event.Handler, @handler_opts
use Commanded.Event.Handler, unquote(handler_opts)

import Ecto.Changeset
import Ecto.Query
Expand Down Expand Up @@ -106,7 +104,7 @@ defmodule Commanded.Projections.Ecto do
end

defp transaction(%Ecto.Multi{} = multi) do
@repo.transaction(multi, timeout: @timeout, pool_timeout: @timeout)
@repo.transaction(multi, timeout: unquote(timeout), pool_timeout: unquote(timeout))
end

defoverridable schema_prefix: 1, schema_prefix: 2
Expand Down