Stopped worker from retrying if doing so wouldn't improve things (#210)

This commit is contained in:
Kieran 2024-04-29 14:06:12 -07:00 committed by GitHub
parent 09cac46e14
commit 3f74f199dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -67,8 +67,8 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do
{:recovered, _} ->
{:error, :retry}
{:error, _message} ->
{:error, :download_failed}
{:error, message} ->
action_on_error(message)
end
end
@ -89,4 +89,18 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do
nil
end
end
defp action_on_error(message) do
# This will attempt re-download at the next indexing, but it won't be retried
# immediately as part of job failure logic
non_retryable_errors = ["Video unavailable"]
if String.contains?(to_string(message), non_retryable_errors) do
Logger.error("yt-dlp download will not be retried: #{inspect(message)}")
{:ok, :non_retry}
else
{:error, :download_failed}
end
end
end

View file

@ -106,6 +106,18 @@ defmodule Pinchflat.Downloading.MediaDownloadWorkerTest do
end)
end
test "does not set the job to retryable if retrying wouldn't fix the issue", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl ->
{:error, "Something something Video unavailable something something", 1}
end)
Oban.Testing.with_testing_mode(:inline, fn ->
{:ok, job} = Oban.insert(MediaDownloadWorker.new(%{id: media_item.id, redownload?: true}))
assert job.state == "completed"
end)
end
test "it ensures error are returned in a 2-item tuple", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl -> {:error, "error", 1} end)