diff --git a/lib/projections/ecto.ex b/lib/projections/ecto.ex index 6caa822..a57a596 100644 --- a/lib/projections/ecto.ex +++ b/lib/projections/ecto.ex @@ -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 @@ -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