From a6ecc184bb78f9b253620af2fcd2596530965b99 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Mon, 11 Dec 2017 20:14:54 +0530 Subject: [PATCH] Dynamic starting worker process * Picking info like gateway and api key from config * Starting worker dynamically --- lib/kuber_hex.ex | 21 ++++----------------- lib/kuber_hex/application.ex | 6 +++--- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/kuber_hex.ex b/lib/kuber_hex.ex index 1c2f9bb9..d9d0887a 100644 --- a/lib/kuber_hex.ex +++ b/lib/kuber_hex.ex @@ -1,24 +1,11 @@ defmodule Kuber.Hex do - use Application - import GenServer, only: [call: 2] - # See http://elixir-lang.org/docs/stable/elixir/Application.html - # for more information on OTP Applications - def start(_type, _args) do - import Supervisor.Spec, warn: false - - children = [ - # Define workers and child supervisors to be supervised - # worker(Kuber.Hex.Worker, [arg1, arg2, arg3]) - ] - - # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html - # for other strategies and supported options - opts = [strategy: :one_for_one, name: Kuber.Hex.Supervisor] - Supervisor.start_link(children, opts) - end + @doc """ + Public API authorize method + Makes an asynchronous authorize call to the Genserver + """ def authorize(worker, amount, card, opts \\ []), do: call(worker, {:authorize, amount, card, opts}) diff --git a/lib/kuber_hex/application.ex b/lib/kuber_hex/application.ex index ffbf3684..6f4afa0f 100644 --- a/lib/kuber_hex/application.ex +++ b/lib/kuber_hex/application.ex @@ -16,11 +16,11 @@ defmodule Kuber.Hex.Application do worker( Kuber.Hex.Worker, [ - Application.get_env(:kuber_hex, Kuber.Hex)[:adapter], # gateway - Application.get_env(:kuber_hex, Kuber.Hex) # options + Application.get_env(:kuber_hex, Kuber.Hex)[:adapter], # gateway + Application.get_env(:kuber_hex, Kuber.Hex), # options(config from application) # Experimental # TODO: This is exposed from the config and is later used to call methods of the lib. - # [name: Application.get_env(:kuber_hex, Kuber.Hex)[:worker_process_name]] + [name: Application.get_env(:kuber_hex, Kuber.Hex)[:worker_process_name]] ]) ]