berrypod/lib/mix/tasks/berrypod/download_images.ex
jamey 9528700862 rename project from SimpleshopTheme to Berrypod
All modules, configs, paths, and references updated.
836 tests pass, zero warnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:23:15 +00:00

42 lines
1.1 KiB
Elixir

defmodule Mix.Tasks.Berrypod.DownloadImages do
@moduledoc """
Enqueues download jobs for product images that haven't been processed yet.
## Usage
mix berrypod.download_images
This task finds all product images with a `src` URL but no linked `image_id`
and enqueues them for download via the ImageDownloadWorker.
Use this to backfill existing products after enabling the image download pipeline.
"""
use Mix.Task
@shortdoc "Enqueue product image downloads"
@impl Mix.Task
def run(_args) do
Mix.Task.run("app.start")
alias Berrypod.Products
alias Berrypod.Sync.ImageDownloadWorker
pending = Products.list_pending_downloads(limit: 10_000)
count = length(pending)
if count == 0 do
Mix.shell().info("No pending product images to download.")
else
Mix.shell().info("Enqueueing #{count} product images for download...")
Enum.each(pending, fn image ->
ImageDownloadWorker.enqueue(image.id)
end)
Mix.shell().info("Done. Images will be processed by Oban workers.")
end
end
end