Skip to content

Commit

Permalink
update super server
Browse files Browse the repository at this point in the history
  • Loading branch information
JoE11-y committed Nov 6, 2024
1 parent 28f8983 commit c534b25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions openfeature/providers/elixir-provider/lib/provider/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ElixirProvider.ServerSupervisor do
@impl true
def init([_args]) do
children = [
ElixirProvider.HttpClient,
ElixirProvider.GoFWebSocketClient,
ElixirProvider.CacheController,
ElixirProvider.DataCollectorHook
Expand Down

0 comments on commit c534b25

Please sign in to comment.