Skip to content

Commit

Permalink
expose request count in LiveView to visualise #226
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 28, 2025
1 parent 4f35220 commit 1d08a93
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/app/api_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ defmodule App.ApiManager do
end

defp schedule_work() do
Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours
Process.send_after(self(), :work, 60 * 1000) # check again in 1 min
end

def get_users() do
# Check how many requests have been made in the last hour:
count = App.Reqlog.req_count_last_hour()
if count < 4920 do
# Get the top 80 users that need to be queried

end
end
end
1 change: 0 additions & 1 deletion lib/app/reqlog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ defmodule App.Reqlog do
# Using `DateTime.add/4` with a negative number to subtract. ;-)
# via: https://elixirforum.com/t/create-time-with-one-hour-plus/3666/5
one_hour_ago = DateTime.utc_now(:second) |> DateTime.add(-3600)

Repo.one(from r in Reqlog, select: count("*"),
where: r.inserted_at > ^one_hour_ago)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/app_web/live/app_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ defmodule AppWeb.AppLive do
created_at: "2010-02-02T08:44:49Z", company: "ideaq"}
# NEXT: prepend avatars to list ...


{:ok, assign(socket, %{data: p, ids: App.User.list_users_avatars()})}
{:ok, assign(socket, %{data: p,
ids: App.User.list_users_avatars(),
count: App.Reqlog.req_count_last_hour()})}
end

def handle_event("sync", value, socket) do
Expand Down
1 change: 1 addition & 0 deletions lib/app_web/live/app_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class="w-20 bg-green-600 hover:bg-green-800 text-white font-bold py-2 px-4 rounded">
Sync
</button>
<h1 class="float-right">{@count}</h1>

<div class="flex flex-row justify-center items-center bg-lime-500">
<h1>Newest person:</h1>
Expand Down

0 comments on commit 1d08a93

Please sign in to comment.