Add maintenance tasks to refresh all artist wikipedia bios
This commit is contained in:
@@ -19,6 +19,12 @@ defmodule MusicLibrary.Artists.Batch do
|
||||
end)
|
||||
end
|
||||
|
||||
def refresh_wikipedia_data do
|
||||
run_on_all_artist_infos(fn artist_info ->
|
||||
Artists.refresh_wikipedia_data_async(artist_info)
|
||||
end)
|
||||
end
|
||||
|
||||
defp run_on_all_artist_infos(fun) do
|
||||
q = from(r in ArtistInfo)
|
||||
stream = Repo.stream(q, max_rows: 50)
|
||||
|
||||
@@ -50,6 +50,10 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
|
||||
:refresh_artists_discogs_jobs,
|
||||
count_jobs("MusicLibrary.Worker.ArtistRefreshDiscogsData")
|
||||
)
|
||||
|> assign(
|
||||
:refresh_artists_wikipedia_jobs,
|
||||
count_jobs("MusicLibrary.Worker.ArtistRefreshWikipediaData")
|
||||
)
|
||||
end
|
||||
|
||||
defp count_jobs(worker) do
|
||||
@@ -94,6 +98,14 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
|
||||
|> put_toast(:info, gettext("Operation started in the background."))}
|
||||
end
|
||||
|
||||
def handle_event("refresh_artists_wikipedia_data", _params, socket) do
|
||||
Artists.Batch.refresh_wikipedia_data()
|
||||
|
||||
{: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} ->
|
||||
|
||||
@@ -80,6 +80,19 @@
|
||||
<.loading :if={@refresh_artists_discogs_jobs > 0} class="size-4" />
|
||||
{gettext("Refresh Discogs data")}
|
||||
</.button>
|
||||
<.button
|
||||
type="button"
|
||||
phx-click="refresh_artists_wikipedia_data"
|
||||
disabled={@refresh_artists_wikipedia_jobs > 0}
|
||||
data-confirm={
|
||||
gettext(
|
||||
"Are you sure you want to refresh Wikipedia data for all artists? This operation can take a long time to complete."
|
||||
)
|
||||
}
|
||||
>
|
||||
<.loading :if={@refresh_artists_wikipedia_jobs > 0} class="size-4" />
|
||||
{gettext("Refresh Wikipedia data")}
|
||||
</.button>
|
||||
</.button_group>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user