Skip to content

Commit

Permalink
add logs with cast not call
Browse files Browse the repository at this point in the history
pushing logs can block, so we should just fire and forget when
attempting to add a log event
  • Loading branch information
peburrows committed Oct 24, 2024
1 parent a548fa1 commit 3794a4d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/statsig_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ defmodule StatsigEx do
def handle_call({:log, event}, _from, state),
do: {:reply, :ok, Map.put(state, :events, [event | state.events])}

def handle_info({:log, event}, state),
do: {:noreply, Map.put(state, :events, [event | state.events])}

def handle_info(
:reload,
%{api_key: key, last_sync: time, prefix: server, reload_interval: i} = state
Expand Down Expand Up @@ -175,15 +178,15 @@ defmodule StatsigEx do
base_event(user, secondary, :config)
|> Map.put("metadata", primary)

GenServer.call(server, {:log, event})
GenServer.cast(server, {:log, event})
end

defp log_exposures(server, user, [primary | secondary], type) do
event =
base_event(user, secondary, type)
|> Map.put("metadata", primary)

GenServer.call(server, {:log, event})
GenServer.cast(server, {:log, event})
end

defp base_event(user, secondary, type) do
Expand Down

0 comments on commit 3794a4d

Please sign in to comment.