diff --git a/components/electric/lib/electric/plug/status.ex b/components/electric/lib/electric/plug/status.ex index 21935b5fc4..cd534a3cbc 100644 --- a/components/electric/lib/electric/plug/status.ex +++ b/components/electric/lib/electric/plug/status.ex @@ -5,25 +5,20 @@ defmodule Electric.Plug.Status do use Plug.Router import Plug.Conn - plug(:match) - plug(:dispatch) + plug :match + plug :dispatch get "/" do - origins = - PostgresConnector.connectors() - |> Enum.map(fn origin -> - case PostgresConnectorMng.status(origin) do - :ready -> {origin, true} - :migration -> {origin, :migration} - _ -> {origin, false} - end - end) + [origin] = PostgresConnector.connectors() - data = %{ - connectors: Map.new(origins) - } + msg = + if :ready == PostgresConnectorMng.status(origin) do + "Connection to Postgres is up!" + else + "Initializing connection to Postgres..." + end - send_resp(conn, 200, Jason.encode!(data)) + send_resp(conn, 200, msg) end match _ do diff --git a/components/electric/lib/electric/postgres/postgres_manager.ex b/components/electric/lib/electric/postgres/postgres_manager.ex index 08317767d0..fec8c9f345 100644 --- a/components/electric/lib/electric/postgres/postgres_manager.ex +++ b/components/electric/lib/electric/postgres/postgres_manager.ex @@ -23,7 +23,7 @@ defmodule Electric.Replication.PostgresConnectorMng do subscription: String.t(), electric_connection: %{host: String.t(), port: pos_integer, dbname: String.t()} }, - state: :reinit | :init | :subscribe | :ready | :migration + state: :init | :subscribe | :ready } end @@ -44,9 +44,9 @@ defmodule Electric.Replication.PostgresConnectorMng do Electric.name(__MODULE__, origin) end - @spec status(Connectors.origin()) :: :init | :subscribe | :ready | :migration + @spec status(Connectors.origin()) :: :init | :subscribe | :ready def status(origin) do - GenServer.call(name(origin), {:status}) + GenServer.call(name(origin), :status) end @impl GenServer @@ -68,8 +68,7 @@ defmodule Electric.Replication.PostgresConnectorMng do end @impl GenServer - def handle_continue(init, %State{origin: origin} = state) - when init == :init or init == :reinit do + def handle_continue(:init, %State{origin: origin} = state) do case initialize_postgres(state) do {:ok, state1} -> :ok = PostgresConnector.start_children(state.config) @@ -79,7 +78,7 @@ defmodule Electric.Replication.PostgresConnectorMng do error -> Logger.error("initialization for postgresql failed with reason: #{inspect(error)}") - {:noreply, schedule_retry(init, state)} + {:noreply, schedule_retry(:init, state)} end end @@ -94,7 +93,7 @@ defmodule Electric.Replication.PostgresConnectorMng do end @impl GenServer - def handle_call({:status}, _from, state) do + def handle_call(:status, _from, state) do {:reply, state.state, state} end diff --git a/e2e/tests/01.01_simple_startup.lux b/e2e/tests/01.01_simple_startup.lux index 12611eb0be..6b9a0273ca 100644 --- a/e2e/tests/01.01_simple_startup.lux +++ b/e2e/tests/01.01_simple_startup.lux @@ -5,7 +5,7 @@ [newshell electric_curl] !curl http://localhost:5133/api/status - ?{"connectors":{"postgres_1":true}} + ??Connection to Postgres is up! [cleanup] - [invoke teardown] \ No newline at end of file + [invoke teardown] diff --git a/examples/beer-stars/README.md b/examples/beer-stars/README.md index 3e7ff4954f..70ea9bb057 100644 --- a/examples/beer-stars/README.md +++ b/examples/beer-stars/README.md @@ -92,7 +92,7 @@ Another service is an Electric sync service running replication on port `5133`: ```shell $ curl http://localhost:5133/api/status -{"connectors":{"postgres_1":true}} +Connection to Postgres is up! ``` Finally, the app backend that talks to GitHub's GraphQL API runs on port `40001`: