Last active
June 14, 2018 17:52
-
-
Save AndrewDryga/8d0029925dd03b5294246943742f5990 to your computer and use it in GitHub Desktop.
Saga: Booking
This file contains hidden or 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 BookingApp.Sage do | |
import Sage | |
@spec book_trip(attrs :: map()) :: {:ok, last_effect :: any(), all_effects :: map()} | {:error, reason :: any()} | |
def book_trip(attrs) do | |
new() | |
|> run(:exchange_rate, &Billing.fetch_currency_exchange_rates/2, &Billing.currency_exchange_rates_circuit_breaker/4) | |
|> run(:authorization, &Billing.authorize_card/2, &Billing.cancel_card_authorization/4) | |
|> run_async(:book_hotel, &HotelsBooking.book/2, &HotelsBooking.cancel_booking/4) | |
|> run_async(:book_car, &CarsBooking.book/2, &CarsBooking.cancel_booking/4) | |
|> run_async(:book_flight, &FlightsBooking.book/2, &FlightsBooking.cancel_booking/4) | |
|> run(:email_confirmation, &Mailer.send_email_confirmation/2) | |
|> run(:charge, &Billing.charge_authorization/2, &Billing.refund_payment/4) | |
|> transaction(Repo, attrs) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment