Skip to content

Commit

Permalink
Dynamic starting worker process
Browse files Browse the repository at this point in the history
* Picking info like gateway and api key from config
* Starting worker dynamically
  • Loading branch information
ashish173 committed Dec 11, 2017
1 parent b899254 commit a6ecc18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
21 changes: 4 additions & 17 deletions lib/kuber_hex.ex
Original file line number Diff line number Diff line change
@@ -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})

Expand Down
6 changes: 3 additions & 3 deletions lib/kuber_hex/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
])
]

Expand Down

0 comments on commit a6ecc18

Please sign in to comment.