Skip to content

Commit

Permalink
💀 additional event triggering proxy (lets hope its lgtm)
Browse files Browse the repository at this point in the history
  • Loading branch information
RustySnek committed Oct 15, 2024
1 parent c05a5f9 commit 0c41f84
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/elixirus/healthcheck/health_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ defmodule Elixirus.Healthcheck.HealthSupervisor do

def init(_args) do
children = [
Supervisor.child_spec({HealthWorker, [LibrusConnection, 10_000]}, id: LibrusConnection),
Supervisor.child_spec({HealthWorker, [ProxyAlive, 10_000]}, id: ProxyAlive)
Supervisor.child_spec({HealthWorker, [LibrusConnection, 10_000]},
id: LibrusConnection,
restart: :permanent
),
Supervisor.child_spec({HealthWorker, [ProxyAlive, 10_000]},
id: ProxyAlive,
restart: :permanent
)
]

Supervisor.init(children, strategy: :one_for_one)
Expand Down
2 changes: 1 addition & 1 deletion lib/elixirus/healthcheck/healthcheck.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ defmodule Elixirus.Healthcheck.Healthcheck do
@moduledoc """
wrapper for Healthcheck genserver
"""

def get_service_status(service), do: GenServer.call(service, {:get_status})
end
1 change: 0 additions & 1 deletion lib/elixirus/healthcheck/services/librus_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ defmodule Elixirus.Healthcheck.Services.LibrusConnection do
) do
{:ok, _} ->
set_proxy(:down)

:up

_ ->
Expand Down
11 changes: 11 additions & 0 deletions lib/elixirus_web/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule ElixirusWeb.Helpers do
"""
alias Elixirus.Types.Grade
alias Elixirus.Types.Period
alias Elixirus.Healthcheck.Healthcheck

use Phoenix.LiveView
require Logger

Expand Down Expand Up @@ -69,6 +71,15 @@ defmodule ElixirusWeb.Helpers do
{:token_error, message, socket}
end

def match_basic_errors(socket, {:error, :timeout}, _asyncs) do
status = Healthcheck.get_service_status(Elixirus.Healthcheck.LibrusConnection)
proxy = System.get_env("USE_PROXY", "no")
Logger.error("Librus connection on timing out: #{status} | proxy after refresh: #{proxy}")

{:error, message,
put_flash(socket, :error, "Timed out. Librus status: #{status}. Try refreshing...")}
end

def match_basic_errors(socket, {:error, message}, _asyncs) do
Logger.error(message)
{:error, message, put_flash(socket, :error, message)}
Expand Down

0 comments on commit 0c41f84

Please sign in to comment.