Stopped worker from retrying if doing so wouldn't improve things (#210)
This commit is contained in:
parent
09cac46e14
commit
3f74f199dc
2 changed files with 28 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue