104 lines
2.1 KiB
Elixir
104 lines
2.1 KiB
Elixir
defmodule DrainCloudCore.Rtc.Application do
|
|
use Application
|
|
|
|
def child_spec(opts) do
|
|
%{
|
|
id: __MODULE__,
|
|
start: {__MODULE__, :start_link, [opts]},
|
|
shutdown: 5_000,
|
|
restart: :permanent,
|
|
type: :supervisor
|
|
}
|
|
end
|
|
def start_link(_) do
|
|
children = [
|
|
DrainCloudCore.Rtc
|
|
]
|
|
|
|
opts = [strategy: :one_for_one, name: DrainCloudCore.Rtc.Supervisor]
|
|
Supervisor.start_link(children, opts)
|
|
end
|
|
end
|
|
|
|
defmodule DrainCloudCore.Rtc do
|
|
alias :mnesia, as: Mnesia
|
|
alias :logger, as: Log
|
|
|
|
use GenServer
|
|
|
|
# Real-time config table schemas
|
|
@config_web [attributes: [
|
|
:host,
|
|
:enable_https,
|
|
:port,
|
|
]]
|
|
|
|
@config_pg [attributes: [
|
|
:host,
|
|
:port,
|
|
:ssl,
|
|
:user,
|
|
:password,
|
|
:db,
|
|
]]
|
|
|
|
|
|
@config_s3 [attributes: [
|
|
:host,
|
|
:port,
|
|
# user / secret / secrets etc...
|
|
]]
|
|
|
|
# def child_spec(opts) do
|
|
# %{
|
|
# id: __MODULE__,
|
|
# start: {__MODULE__, :start_link, [opts]},
|
|
# shutdown: 5_000,
|
|
# restart: :permanent,
|
|
# type: :worker
|
|
# }
|
|
# end
|
|
|
|
def start_link(default) when is_list(default) do
|
|
GenServer.start_link(__MODULE__, default)
|
|
end
|
|
|
|
@impl true
|
|
def init(stack) do
|
|
{:ok, stack}
|
|
end
|
|
|
|
@impl true
|
|
def handle_call(:pop, _from, [head | tail]) do
|
|
{:reply, head, tail}
|
|
end
|
|
|
|
@impl true
|
|
def handle_cast({:push, element}, state) do
|
|
{:noreply, [element | state]}
|
|
end
|
|
|
|
def fetch_config() do
|
|
# Mnesia.read()
|
|
end
|
|
def init() do
|
|
Log.info("[#{__MODULE__}] start initializin RTC subsystems")
|
|
|
|
if Mnesia.create_schema([node()]) != :ok do
|
|
Log.warning("[#{__MODULE__}] schema #{node()} not created. skipping")
|
|
end
|
|
|
|
if Mnesia.create_table(DrainCloudRtcWeb, @config_web) != {:atomic, :ok} do
|
|
Log.warning("[#{__MODULE__}] table config_web not created. skipping")
|
|
end
|
|
|
|
if Mnesia.create_table(DrainCloudRtcPG, @config_pg) != {:atomic, :ok} do
|
|
Log.warning("[#{__MODULE__}] schema config_pg not created. skipping")
|
|
end
|
|
|
|
if Mnesia.create_table(DrainCloudRtcS3, @config_s3) != {:atomic, :ok} do
|
|
Log.warning("[#{__MODULE__}] schema config_s3 not created. skipping")
|
|
end
|
|
end
|
|
end
|