Current section
Files
Jump to
Current section
Files
lib/aphora.ex
# Copyright 2019 Schicksal
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
defmodule Aphora do
@moduledoc """
This module is the `Supervisor` for `Aphora` as well as the main interface for the `GenServer` in which you can create a `t:Aphora.Worker.aphora_id/0` by using `new_id/0`.
"""
use Application
def start(_type, _args) do
children = [
{Aphora.Worker,
%{
datacenter: Aphora.Config.get_datacenter(),
worker: Aphora.Config.get_worker(),
epoch: Aphora.Config.get_epoch()
}}
]
opts = [strategy: :one_for_one, name: __MODULE__]
Supervisor.start_link(children, opts)
end
@doc since: "0.1.0"
@spec new_id() :: {:ok, Aphora.Worker.aphora_id()} | {:error, atom()}
def new_id do
GenServer.call(Aphora.Worker, :new_id)
end
end