Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requeue seems inconsistent with the general use of Ecto.Multi #62

Open
Theuns-Botha opened this issue Mar 21, 2020 · 0 comments
Open

Requeue seems inconsistent with the general use of Ecto.Multi #62

Theuns-Botha opened this issue Mar 21, 2020 · 0 comments

Comments

@Theuns-Botha
Copy link

Theuns-Botha commented Mar 21, 2020

One would typically want to handle a multi in the following pattern:

{existing multi}
|> Ecto.Multi.merge(fn %{job: job} = multi ->
     Ecto.Multi.new()
     |> __MODULE__.requeue("requeue_job", job)
end)
|> MyApp.Repo.transaction()
|> case do
       {:error, :non_failed_job} -> do_something
    end

The above would also allow you to pass the error on to fallback controllers and such.

However, the way the requeue function is currently implimented, it does not just register an error on the multi, but rather returns an error. This forces one do add a non-elegant error handling block somewhere midstream something like the following.

|> Ecto.Multi.merge(fn %{job: job} = multi ->
          Ecto.Multi.new()
          |> __MODULE__.requeue("requeue_job", job)
          |> case do
            {:error, :non_failed_job} ->
              Ecto.Multi.new()
              |> Ecto.Multi.error("requeue_job", {:error, :non_failed_job})

            any ->
              any
          end
        end)
|> MyApp.Repo.transaction()
|> case do
       {:error, :non_failed_job} -> do_something
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant