Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions lib/live_admin/components/resource/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,12 @@ defmodule LiveAdmin.Components.Container.Index do

job =
Task.Supervisor.async_nolink(LiveAdmin.Task.Supervisor, fn ->
socket.assigns.selected
|> Enum.with_index()
|> Enum.each(fn {id, idx} ->
selected = socket.assigns.selected
total = Enum.count(selected)

selected
|> Enum.with_index(1)
|> Enum.reduce_while(:ok, fn {id, idx}, _ ->
try do
id
|> Resource.find(resource, prefix, repo, config)
Expand All @@ -405,28 +408,32 @@ defmodule LiveAdmin.Components.Container.Index do
end

LiveAdmin.PubSub.update_job(session.id, self(),
progress: idx / Enum.count(socket.assigns.selected),
progress: idx / total,
label: name
)

{:cont, :ok}
rescue
error ->
Logger.error(inspect(error))

LiveAdmin.PubSub.announce(
session.id,
:error,
trans("%{name} encountered an error and stopped", inter: [name: name])
)
after
LiveAdmin.PubSub.update_job(session.id, self(), progress: 1)
{:halt, :error}
end
end)
|> case do
:ok ->
LiveAdmin.PubSub.announce(
session.id,
:info,
trans("%{name} complete", inter: [name: name])
)

LiveAdmin.PubSub.announce(
session.id,
:info,
trans("%{name} complete", inter: [name: name])
)
:error ->
LiveAdmin.PubSub.announce(
session.id,
:error,
trans("%{name} encountered an error and stopped", inter: [name: name])
)
end
end)

LiveAdmin.PubSub.update_job(session.id, job.pid, progress: 0, label: to_string(name))
Expand Down
Loading