From 299dee4b854d6a6780630054ed9dcc7d4e977f99 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 2 Nov 2025 21:02:34 +0000 Subject: [PATCH] Add maintenance page Some actions are missing --- .../components/layouts/app.html.heex | 9 +++ .../live/maintenance_live/index.ex | 49 +++++++++++++ .../live/maintenance_live/index.html.heex | 60 ++++++++++++++++ lib/music_library_web/router.ex | 2 + priv/gettext/default.pot | 68 +++++++++++++++++++ priv/gettext/en/LC_MESSAGES/default.po | 68 +++++++++++++++++++ 6 files changed, 256 insertions(+) create mode 100644 lib/music_library_web/live/maintenance_live/index.ex create mode 100644 lib/music_library_web/live/maintenance_live/index.html.heex diff --git a/lib/music_library_web/components/layouts/app.html.heex b/lib/music_library_web/components/layouts/app.html.heex index 2adac50e..088970f8 100644 --- a/lib/music_library_web/components/layouts/app.html.heex +++ b/lib/music_library_web/components/layouts/app.html.heex @@ -120,6 +120,15 @@ /> {gettext("Lotus")} + <.dropdown_link href={~p"/dev/maintenance"}> + <.icon + name="hero-wrench-screwdriver" + class="h-4 w-4 mr-2" + aria-hidden="true" + data-slot="icon" + /> + {gettext("Maintenance")} + <.dropdown_separator /> <.dropdown_link href={~p"/login"}> <.icon diff --git a/lib/music_library_web/live/maintenance_live/index.ex b/lib/music_library_web/live/maintenance_live/index.ex new file mode 100644 index 00000000..e38e4401 --- /dev/null +++ b/lib/music_library_web/live/maintenance_live/index.ex @@ -0,0 +1,49 @@ +defmodule MusicLibraryWeb.MaintenanceLive.Index do + use MusicLibraryWeb, :live_view + + require Logger + + alias MusicLibrary.Records.Batch + alias MusicLibrary.Repo + + def mount(_params, _session, socket) do + {:ok, + socket + |> assign( + page_title: gettext("Maintenance"), + current_section: :maintenance + )} + end + + def handle_event("refresh_records_musicbrainz_data", _params, socket) do + Batch.refresh_musicbrainz_data() + + {:noreply, + socket + |> put_toast(:info, gettext("Operation started in the background."))} + end + + def handle_event("generate_record_embeddings", _params, socket) do + Batch.generate_embeddings() + + {:noreply, + socket + |> put_toast(:info, gettext("Operation started in the background."))} + end + + def handle_event("db_vacuum", _params, socket) do + case Repo.vacuum() do + {:ok, _result} -> + {:noreply, + socket + |> put_toast(:info, gettext("Database vacuumed successfully."))} + + {:error, reason} -> + Logger.error("Database vacuum failed: #{inspect(reason)}.") + + {:noreply, + socket + |> put_toast(:error, "Database vacuum failed: #{inspect(reason)}.")} + end + end +end diff --git a/lib/music_library_web/live/maintenance_live/index.html.heex b/lib/music_library_web/live/maintenance_live/index.html.heex new file mode 100644 index 00000000..6ff28e09 --- /dev/null +++ b/lib/music_library_web/live/maintenance_live/index.html.heex @@ -0,0 +1,60 @@ + +
+

+ {gettext("Maintenance")} +

+

+ {gettext("Records")} +

+

+ {gettext( + "Run operations on the entire record database. Monitor execution via the Oban dashboard." + )} +

+
    +
  • + <.button type="button" phx-click="refresh_records_musicbrainz_data"> + {gettext("Refresh MusicBrainz data")} + + <.button type="button" phx-click="generate_record_embeddings"> + {gettext("Regenerate record embeddings")} + +
  • +
+

+ {gettext("Artists")} +

+

+ {gettext( + "Run operations on the entire artist database. Monitor execution via the Oban dashboard." + )} +

+
    +
  • + <.button disabled type="button" phx-click="refresh_artists_musicbrainz_data"> + {gettext("Refresh MusicBrainz data")} + + <.button disabled type="button" phx-click="refresh_artists_discogs_data"> + {gettext("Refresh Discogs data")} + +
  • +
+

+ {gettext("Database")} +

+

+ {gettext("Run lower-level operations on the database")} +

+
    +
  • + <.button + type="button" + phx-click="db_vacuum" + phx-disable-with={gettext("Running vacuum...")} + > + {gettext("Vacuum")} + +
  • +
+
+
diff --git a/lib/music_library_web/router.ex b/lib/music_library_web/router.ex index 630d5da3..d3eb3dbc 100644 --- a/lib/music_library_web/router.ex +++ b/lib/music_library_web/router.ex @@ -104,6 +104,8 @@ defmodule MusicLibraryWeb.Router do oban_dashboard "/oban" lotus_dashboard("/lotus") + + live "/maintenance", MusicLibraryWeb.MaintenanceLive.Index, :index end end end diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index bdcf3333..5f4336ad 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -368,6 +368,7 @@ msgstr "" msgid "Refresh cover" msgstr "" +#: lib/music_library_web/live/maintenance_live/index.html.heex #: lib/music_library_web/live/stats_live/index.html.heex #, elixir-autogen, elixir-format msgid "Records" @@ -1498,3 +1499,70 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Today" msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Artists" +msgstr "" + +#: lib/music_library_web/components/layouts/app.html.heex +#: lib/music_library_web/live/maintenance_live/index.ex +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Maintenance" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Refresh Discogs data" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Refresh MusicBrainz data" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Regenerate record embeddings" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Run operations on the entire artist database. Monitor execution via the Oban dashboard." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Run operations on the entire record database. Monitor execution via the Oban dashboard." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Database" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.ex +#, elixir-autogen, elixir-format +msgid "Database vacuumed successfully." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.ex +#, elixir-autogen, elixir-format +msgid "Operation started in the background." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Run lower-level operations on the database" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Running vacuum..." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Vacuum" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 53264876..7685c94e 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -368,6 +368,7 @@ msgstr "" msgid "Refresh cover" msgstr "" +#: lib/music_library_web/live/maintenance_live/index.html.heex #: lib/music_library_web/live/stats_live/index.html.heex #, elixir-autogen, elixir-format msgid "Records" @@ -1498,3 +1499,70 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Today" msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format, fuzzy +msgid "Artists" +msgstr "" + +#: lib/music_library_web/components/layouts/app.html.heex +#: lib/music_library_web/live/maintenance_live/index.ex +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Maintenance" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format, fuzzy +msgid "Refresh Discogs data" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format, fuzzy +msgid "Refresh MusicBrainz data" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Regenerate record embeddings" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Run operations on the entire artist database. Monitor execution via the Oban dashboard." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Run operations on the entire record database. Monitor execution via the Oban dashboard." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Database" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.ex +#, elixir-autogen, elixir-format +msgid "Database vacuumed successfully." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.ex +#, elixir-autogen, elixir-format, fuzzy +msgid "Operation started in the background." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Run lower-level operations on the database" +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Running vacuum..." +msgstr "" + +#: lib/music_library_web/live/maintenance_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Vacuum" +msgstr ""