x3m_system v0.1.0 X3m.System.Facade View Source

defmodule MyFacade do
  use     X3m.System.Facade

  route :do_something,      MyController          # calls MyController.do_something(params)
  route :do_something_else, {MyController, :else} # calls MyController.else(params)

  on_alarm {:expire!, id}, fn ->
    with {:ok, _} <- Offer.expire!(id),
         do:         :ok
  end

  def handle_call({:get_timezone, :point, lat, long, metadata}=payload, from, state) do
    hash = hash(:get_timezone, payload)
    execute(state, hash, from, fn ->
      Logger.metadata metadata
      Timezone.get_timezone(:point, lat, long)
    end)
    {:noreply, state}
  end
end

Facade is GenServer. It is used as:

pid = :global.whereis_name MyFacade
cmd1 = {:do_something, %{"lat" => "21", "long" => "21"}}
cmd2 = {:do_something_else, %{"lat" => "21", "long" => "21"}, [req_id: "1231231"]}
GenServer.call pid, cmd1
GenServer.call pid, cmd2

cmd is tuple of 2 or 3 elements. First one is route, second one are params that will be proxied to controller, and optional 3rd is Logger metadata that will be set for that task.

Result of MyController.do_something/1 will be sent in reply to GenServer.call. If format of message is different, manual handle_call/3 handler can be set.

Link to this section Summary

Link to this section Functions

Returns specification for X3m.System.Facade.Supervisor.

Link to this macro

on_alarm(msg, fun) View Source (macro)

Link to this macro

route(cmd, controller) View Source (macro)