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 = case configured? do true -> # Queue is the shared agent between the recorder and the poller {:ok, queue} = PerfAgent.TransactionQueue.start_link() # Starting hackney pool for requests PerfAgent.Network.start_pool() [ worker(PerfAgent.Poller, [queue], restart: :transient), worker(PerfAgent.Recorder, [queue], restart: :transient) ] false -> [] end opts = [strategy: :one_for_one, name: PerfAgent.Supervisor] Supervisor.start_link(children, opts) 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