How can I improve this migration script?

Any opinions on how I can improve this script?

# Script for getting and parsing exif data
#
# mix run priv/repo/parse_exif.exs

alias PolymorphicProductions.Social.Pic
alias PolymorphicProductions.Social
alias PolymorphicProductions.Repo

defmodule Processor do
  def fetch_image(%{asset: asset} = row) do
    charlist = asset |> URI.encode() |> to_charlist

    {:ok, resp} =
      :httpc.request(:get, {charlist, [{'Range', 'bytes=0-4000'}]}, [], body_format: :binary)

    {_status, _headers, body} = resp
    {Exexif.exif_from_jpeg_buffer(body), row}
  end

  def write_row({{:ok, exif}, pic}) do
    # Uses ecto 
    {:ok, _pic} = Social.update_pic(pic, %{meta: exif})
  end

  def write_row(_) do
  end
end

Pic
|> Repo.all()
|> Enum.map(fn result -> Task.async(Processor, :fetch_image, [result]) end)
|> Enum.map(&Task.await/1)
|> Enum.map(fn result -> Processor.write_row(result) end)

blaaa, looks like in productions this will not work :frowning:

iex(polymorphic_productions@127.0.0.1)9> Exexif.exif_from_jpeg_buffer(body)
** (KeyError) key :exif not found in: %{}
    (exexif) lib/exexif.ex:141: Exexif.extract_thumbnail/1
    (exexif) lib/exexif.ex:67: Exexif.read_exif/1

That looks more like there is no exif in the jpeg image?

well there is different return for that.
Normally returns {:error, reason}

A quick scan of the code suggests that maybe there is an exif block, but no exif data in it. Is there any chance you can send me the image content (or url) thats causing this? Happy to take a look over my morning coffee…

yeah it was the image, it was failing at something exif was not accounting for thus it was failing at
lib/exexif.ex:141: Exexif.extract_thumbnail/1

I wrapped the function in a try and just dropped that row