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

Update Ecto.Multi.run example #48

Merged
merged 2 commits into from
May 16, 2019
Merged

Update Ecto.Multi.run example #48

merged 2 commits into from
May 16, 2019

Conversation

darksheik
Copy link
Collaborator

My jobs did not run initially after upgrading to the latest release, as it seems the new spec of Ecto.Multi.run is now that the 3rd arg now is a function with arity 2. (current Ecto is 3.1.4)

Updating example in ecto_job doc to reflect that change.

From Ecto.Multi:

[Ecto.Multi] Ecto.Multi.run/3 now receives the repo in which the transaction is executing as the first argument to functions, and the changes so far as the second argument

Code:

  @doc """
  Adds a function to run as part of the multi.

  The function should return either `{:ok, value}` or `{:error, value}`,
  and receives the repo as the first argument, and the changes so far
  as the second argument.

  ## Example

      Ecto.Multi.run(multi, :write, fn _repo, %{image: image} ->
        with :ok <- File.write(image.name, image.contents) do
          {:ok, nil}
        end
      end)
  """
  @spec run(t, name, run) :: t
  def run(multi, name, run) when is_function(run, 2) do
    add_operation(multi, name, {:run, run})
  end

README.md Outdated Show resolved Hide resolved
Sounds good to me.  Some folks might want to use that additional info, good to know at a glance.

Co-Authored-By: Vítor Luís dos Santos Trindade <emailreservadovitor@gmail.com>
@mbuhot
Copy link
Owner

mbuhot commented May 16, 2019

Thanks @darksheik @VitorTrin 👍

@mbuhot mbuhot merged commit 17f2b33 into master May 16, 2019
@mbuhot mbuhot deleted the ecto_multi_arity_2 branch May 16, 2019 01:17
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

Successfully merging this pull request may close these issues.

3 participants