Last active
April 20, 2020 13:12
-
-
Save mmmries/19b587851c117464749c0317a3112c02 to your computer and use it in GitHub Desktop.
Kick off job after saving changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule UserController do | |
def create(params) do | |
changeset = params | |
|> cast([:name, :email]) | |
|> validate_required([:email]) | |
|> validate_other_stuff() | |
WithSideEffects.create(changeset) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule WithSideEffects do | |
def create(changeset) do | |
case Repo.insert(changeset) do | |
{:ok, record} -> | |
async_publish_job(record, :create) | |
{:error, changeset} -> | |
{:error, changeset} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment