Skip to content

Instantly share code, notes, and snippets.

@rafaels88
Created September 11, 2018 10:24
Show Gist options
  • Save rafaels88/f1a4128a5c277ea57a00ad3df3aa24e4 to your computer and use it in GitHub Desktop.
Save rafaels88/f1a4128a5c277ea57a00ad3df3aa24e4 to your computer and use it in GitHub Desktop.
Quiqup.DispatchOrderStagePipeline
defmodule Quiqup.DispatchOrderStagePipeline do
def call(%{order_id: order_id}) do
with {:ok, %{courier: courier} = order} <- validate_order(order),
{:ok, true} <- courier_available?(courier),
{:ok, next_stage_slug} <- next_stage_slug_by(order),
{:persist_stage, {:ok, %Stage{} = stage}}
<- {:persist_stage, %{order: order} |> create_stage(next_stage_slug)},
{:push_notification, :ok}
<- {:push_notification, push_notification(%{courier: courier, stage: stage})},
{:emit_event, :ok}
<- {:emit_event, emit_event(%{courier: courier, stage: stage})} do
{:ok, stage}
else
e -> {:error, e}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment