diff --git a/openfeature/providers/elixir-provider/lib/provider/http_client.ex b/openfeature/providers/elixir-provider/lib/provider/http_client.ex index df60b45a951..265c7b273db 100644 --- a/openfeature/providers/elixir-provider/lib/provider/http_client.ex +++ b/openfeature/providers/elixir-provider/lib/provider/http_client.ex @@ -3,6 +3,8 @@ defmodule ElixirProvider.HttpClient do Handles HTTP requests to the GO Feature Flag API. """ + use GenServer + # Define a struct to store HTTP connection, endpoint, and other configuration details defstruct [:conn, :endpoint, :headers] @@ -12,6 +14,29 @@ defmodule ElixirProvider.HttpClient do headers: list() } + @spec start_link() :: GenServer.on_start() + def start_link() do + GenServer.start_link(__MODULE__, :ok, name: __MODULE__) + end + + def stop() do + GenServer.stop(__MODULE__) + end + + @impl true + def init([]) do + {:ok, %__MODULE__{}} + end + + @spec start_http_connection(any()) :: + {:error, + %{ + :__exception__ => true, + :__struct__ => Mint.HTTPError | Mint.TransportError, + :reason => any(), + optional(:module) => any() + }} + | {:ok, ElixirProvider.HttpClient.t()} def start_http_connection(options) do uri = URI.parse(options.endpoint) scheme = if uri.scheme == "https", do: :https, else: :http diff --git a/openfeature/providers/elixir-provider/lib/provider/provider.ex b/openfeature/providers/elixir-provider/lib/provider/provider.ex index 97f979c3ba1..106592af709 100644 --- a/openfeature/providers/elixir-provider/lib/provider/provider.ex +++ b/openfeature/providers/elixir-provider/lib/provider/provider.ex @@ -35,7 +35,6 @@ defmodule ElixirProvider.Provider do @impl true def initialize(%__MODULE__{} = provider, domain, _context) do {:ok, http_client} = HttpClient.start_http_connection(provider.options) - CacheController.start_link() {:ok, data_collector_hook} = DataCollectorHook.start(provider.options, http_client) {:ok, ws} = GoFWebSocketClient.connect(provider.options.endpoint) diff --git a/openfeature/providers/elixir-provider/lib/provider/server_supervisor.ex b/openfeature/providers/elixir-provider/lib/provider/server_supervisor.ex index c4411f575a5..66105582c45 100644 --- a/openfeature/providers/elixir-provider/lib/provider/server_supervisor.ex +++ b/openfeature/providers/elixir-provider/lib/provider/server_supervisor.ex @@ -8,6 +8,7 @@ defmodule ElixirProvider.ServerSupervisor do @impl true def init([_args]) do children = [ + ElixirProvider.HttpClient, ElixirProvider.GoFWebSocketClient, ElixirProvider.CacheController, ElixirProvider.DataCollectorHook