-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move actvity monitoring state into a
GenSever
and add calls from ea…
…ch GQL field
- Loading branch information
Joel Abshier
committed
Oct 4, 2021
1 parent
4d032a8
commit 12bf5ce
Showing
8 changed files
with
95 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
defmodule ActivityMonitor do | ||
@activity_server GenServer.whereis(ActivityServer) | ||
def update_resolver_activity(key), do: @activity_server |> GenServer.cast({:update, key}) | ||
def fetch_resolver_activity(key), do: @activity_server |> GenServer.call({:get, key}) | ||
def update_resolver_activity(key), do: context() |> GenServer.cast({:update, key}) | ||
def fetch_resolver_activity(key), do: context() |> GenServer.call({:get, key}) | ||
|
||
defp context(), do: GenServer.whereis(ActivityServer) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule ActivityServer do | ||
use GenServer | ||
|
||
def start_link(_), do: GenServer.start_link(__MODULE__, %{}, name: ActivityServer) | ||
def init(_), do: {:ok, %{}} | ||
|
||
def handle_cast({:update, key}, state) do | ||
{:noreply, Map.update(state, key, 1, &(&1 + 1))} | ||
end | ||
|
||
def handle_call({:get, key}, _from, state) do | ||
if Map.has_key?(state, key) do | ||
{:reply, {:ok, Map.get(state, key)}, state} | ||
else | ||
{:reply, {:error, "Requested key: #{key} is invalid"}, state} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule UserPreferencesWeb.Resolvers.Activity do | ||
def get_activity(_, args, _) do | ||
ActivityMonitor.update_resolver_activity("get_activity") | ||
ActivityMonitor.fetch_resolver_activity(args.key) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters