Skip to content

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

@Theuns-Botha

Description

@Theuns-Botha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions