Migrate from embedded covers to assets

This commit is contained in:
Claudio Ortolina
2025-09-01 16:10:50 +03:00
parent cbf567a502
commit dc77d337c0
19 changed files with 80 additions and 144 deletions
+3 -2
View File
@@ -1,14 +1,15 @@
defmodule MusicLibrary.Worker.ExtractColors do
use Oban.Worker, queue: :heavy_writes, max_attempts: 3
alias MusicLibrary.{Colors, Records}
alias MusicLibrary.{Assets, Colors, Records}
@impl Oban.Worker
def perform(%Oban.Job{args: %{"id" => record_id, "method" => method}}) do
record = MusicLibrary.Records.get_record!(record_id)
asset = Assets.get!(record.cover_hash)
method = String.to_existing_atom(method)
with {:ok, colors} <- Colors.extract_colors(record.cover_data, method),
with {:ok, colors} <- Colors.extract_colors(asset.content, method),
{:ok, updated_record} <- Records.update_record(record, %{dominant_colors: colors}) do
MusicLibrary.Records.notify_update(updated_record)
end