Packages
rambla
1.2.6
1.5.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0
0.16.6
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.0
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.1
0.13.0
0.12.2
0.12.1
0.11.1
0.11.0
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
Easy publishing to many different targets. Supported back-ends: - Rabbit [Amqp](https://hexdocs.pm/amqp/) - Redis [Redix](https://hexdocs.pm/redix) - Http [:httpc](http://erlang.org/doc/man/httpc.html) - Smtp [:gen_smtp](https://hexdocs.pm/gen_smtp) - Slack [Envío](https://hexdocs.pm/envio)
Current section
Files
Jump to
Current section
Files
lib/mix/commons.ex
if match?({:module, AMQP.Channel}, Code.ensure_compiled(AMQP.Channel)) do
defmodule Rambla.Tasks.Utils do
@moduledoc false
defmacro __using__(opts \\ []) do
logger =
opts
|> Keyword.get(:logger, [])
|> Keyword.put_new(:level, :warn)
quote do
require Logger
@switches [
connection: :string,
options: :string
]
@aliases for {k, _} <- @switches,
do: {k |> to_string |> String.at(0) |> String.to_atom(), k}
@impl Mix.Task
@doc false
def run([command, name | args]) when command in @commands do
Logger.configure(unquote(logger))
Process.flag(:trap_exit, true)
{opts, _} = OptionParser.parse!(args, aliases: @aliases, strict: @switches)
connection =
case Keyword.get(opts, :connection, Application.get_env(:rambla, :amqp)) do
uri when is_binary(uri) ->
uri
params when is_list(params) ->
port = if params[:port], do: ":#{params[:port]}", else: ""
"amqp://#{params[:username]}:#{params[:password]}@#{params[:host]}#{port}"
nil ->
Mix.raise(
"The connection string must be either passed as -c option or set in `config :rambla, :amqp`"
)
end
with {:ok, conn} <- AMQP.Connection.open(connection),
{:ok, chan} = AMQP.Channel.open(conn),
opts =
opts
|> Keyword.get(:options, "")
|> String.replace(~r/:(?=\d)/, ": ")
|> String.replace(~r/:(?=\w)/, ": :"),
{opts, _} <- Code.eval_string("[" <> opts <> "]"),
{:ok, result} <- do_command(chan, String.to_atom(command), name, opts) do
Mix.shell().info("Success. " <> inspect(result))
else
amqp_base_error ->
Mix.raise("Cannot execute command on target. Error:\n" <> inspect(amqp_base_error))
end
__MODULE__
|> Mix.Task.task_name()
|> Mix.Task.reenable()
end
@doc false
def run(_),
do:
Mix.raise(
"Usage: mix #{Mix.Task.task_name(__MODULE__)} (" <>
Enum.join(@commands, "|") <> ") name [opts]"
)
end
end
end
end