Current section

Files

Jump to
perf_agent lib perf_agent.ex
Raw

lib/perf_agent.ex

defmodule PerfAgent do
@moduledoc """
Entry point for Perf Agent
"""
use Application
@version Mix.Project.config[:version]
@doc """
Application callback to start Perf Agent
"""
@spec start(Application.app, Application.start_type) :: :ok | {:error, term}
def start(_type \\ :normal, _args \\ []) do
import Supervisor.Spec, warn: false
children = []
opts = [strategy: :one_for_one, name: PerfAgent.Supervisor]
result = Supervisor.start_link(children, opts)
if configured? do
# Queue is the shared agent between the recorder and the poller
{:ok, queue} = PerfAgent.TransactionQueue.start_link()
{:ok, _} = PerfAgent.Poller.start_link(queue)
{:ok, recorder} = PerfAgent.Recorder.start_link(queue)
# Put recorder in application config to access from plug
Application.put_env(:perf_agent, :recorder, recorder)
end
result
end
@doc """
Checks if the required configuration params are set.
Application will take no action if not set.
"""
@spec configured? :: boolean
def configured? do
Application.get_env(:perf_agent, :api_key) != nil
end
def version(), do: @version
end