chore: merged different progress reporters

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-01 17:12:49 +02:00
parent 79ee67c2e0
commit f6425de51d
8 changed files with 343 additions and 184 deletions

View File

@@ -1,45 +1,31 @@
defmodule BDS.Maintenance.Progress do
@moduledoc false
def progress_callback(opts) do
case Keyword.get(opts, :on_progress) do
callback when is_function(callback, 2) -> callback
_other -> nil
end
end
def report_metadata_diff_phase(nil, _current, _total, _label), do: :ok
def progress_callback(opts), do: BDS.ProgressReporter.callback(opts)
def report_metadata_diff_phase(callback, current, total, label) do
value = if total <= 1, do: 0.0, else: (current - 1) / total
callback.(value, "#{label} (#{current}/#{total})")
:ok
progress = if total <= 1, do: 0.0, else: (current - 1) / total
BDS.ProgressReporter.report_phase(callback, progress, "#{label} (#{current}/#{total})")
end
def report_metadata_diff_complete(nil), do: :ok
def report_metadata_diff_complete(callback) do
callback.(1.0, "Metadata diff complete")
:ok
end
def report_started(nil, _total, _label), do: :ok
def report_started(callback, 0, label) do
callback.(1.0, label)
:ok
BDS.ProgressReporter.report_phase(callback, 1.0, "Metadata diff complete")
end
def report_started(callback, total, label) do
callback.(0.05, "#{label} (0/#{total})")
:ok
BDS.ProgressReporter.report_count_started(callback, total, label,
verb: nil,
start_progress: 0.05,
empty_message: label,
message_style: :label
)
end
def report_progress(nil, _current, _total, _label), do: :ok
def report_progress(_callback, _current, 0, _label), do: :ok
def report_progress(callback, current, total, label) do
callback.(0.05 + 0.95 * (current / total), "#{label} (#{current}/#{total})")
:ok
BDS.ProgressReporter.report_count_progress(callback, current, total, label,
verb: nil,
start_progress: 0.05,
message_style: :label
)
end
end