Misc refactors 2024-03-15 (#90)
* Fixed TV show output template * Discard jobs if record not found; hopefully addressed timing-related source deletion bug
This commit is contained in:
parent
b633d0f75c
commit
6e7e8dc96c
13 changed files with 54 additions and 9 deletions
|
|
@ -6,6 +6,8 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do
|
|||
unique: [period: :infinity, states: [:available, :scheduled, :retryable, :executing]],
|
||||
tags: ["media_item", "media_fetching"]
|
||||
|
||||
require Logger
|
||||
|
||||
alias __MODULE__
|
||||
alias Pinchflat.Tasks
|
||||
alias Pinchflat.Repo
|
||||
|
|
@ -42,6 +44,9 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do
|
|||
else
|
||||
:ok
|
||||
end
|
||||
rescue
|
||||
Ecto.NoResultsError -> Logger.info("#{__MODULE__} discarded: media item #{media_item_id} not found")
|
||||
Ecto.StaleEntryError -> Logger.info("#{__MODULE__} discarded: media item #{media_item_id} stale")
|
||||
end
|
||||
|
||||
defp download_media_and_schedule_jobs(media_item) do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pinchflat.FastIndexing.FastIndexingWorker do
|
|||
unique: [period: :infinity, states: [:available, :scheduled, :retryable]],
|
||||
tags: ["media_source", "fast_indexing"]
|
||||
|
||||
require Logger
|
||||
|
||||
alias __MODULE__
|
||||
alias Pinchflat.Tasks
|
||||
alias Pinchflat.Sources
|
||||
|
|
@ -41,6 +43,9 @@ defmodule Pinchflat.FastIndexing.FastIndexingWorker do
|
|||
else
|
||||
:ok
|
||||
end
|
||||
rescue
|
||||
Ecto.NoResultsError -> Logger.info("#{__MODULE__} discarded: source #{source_id} not found")
|
||||
Ecto.StaleEntryError -> Logger.info("#{__MODULE__} discarded: source #{source_id} stale")
|
||||
end
|
||||
|
||||
defp reschedule_indexing(source) do
|
||||
|
|
|
|||
|
|
@ -62,5 +62,8 @@ defmodule Pinchflat.FastIndexing.MediaIndexingWorker do
|
|||
end
|
||||
|
||||
:ok
|
||||
rescue
|
||||
Ecto.NoResultsError -> Logger.info("#{__MODULE__} discarded: source #{source_id} not found")
|
||||
Ecto.StaleEntryError -> Logger.info("#{__MODULE__} discarded: source #{source_id} stale")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -196,13 +196,14 @@ defmodule Pinchflat.Media do
|
|||
def delete_media_item(%MediaItem{} = media_item, opts \\ []) do
|
||||
delete_files = Keyword.get(opts, :delete_files, false)
|
||||
|
||||
Tasks.delete_tasks_for(media_item)
|
||||
|
||||
if delete_files do
|
||||
{:ok, _} = delete_media_files(media_item)
|
||||
end
|
||||
|
||||
# Should delete these no matter what
|
||||
delete_internal_metadata_files(media_item)
|
||||
Tasks.delete_tasks_for(media_item)
|
||||
Repo.delete(media_item)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
|||
# in an infinite loop.
|
||||
unique: [period: 600]
|
||||
|
||||
require Logger
|
||||
|
||||
alias __MODULE__
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Tasks
|
||||
|
|
@ -47,5 +49,8 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
|||
})
|
||||
|
||||
:ok
|
||||
rescue
|
||||
Ecto.NoResultsError -> Logger.info("#{__MODULE__} discarded: source #{source_id} not found")
|
||||
Ecto.StaleEntryError -> Logger.info("#{__MODULE__} discarded: source #{source_id} stale")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorker do
|
|||
unique: [period: :infinity, states: [:available, :scheduled, :retryable]],
|
||||
tags: ["media_source", "media_collection_indexing"]
|
||||
|
||||
require Logger
|
||||
|
||||
alias __MODULE__
|
||||
alias Pinchflat.Tasks
|
||||
alias Pinchflat.Sources
|
||||
|
|
@ -90,6 +92,9 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorker do
|
|||
# perform a no-op
|
||||
:ok
|
||||
end
|
||||
rescue
|
||||
Ecto.NoResultsError -> Logger.info("#{__MODULE__} discarded: source #{source_id} not found")
|
||||
Ecto.StaleEntryError -> Logger.info("#{__MODULE__} discarded: source #{source_id} stale")
|
||||
end
|
||||
|
||||
defp reschedule_indexing(source) do
|
||||
|
|
|
|||
|
|
@ -103,6 +103,8 @@ defmodule Pinchflat.Sources do
|
|||
def delete_source(%Source{} = source, opts \\ []) do
|
||||
delete_files = Keyword.get(opts, :delete_files, false)
|
||||
|
||||
Tasks.delete_tasks_for(source)
|
||||
|
||||
source
|
||||
|> Media.list_media_items_for()
|
||||
|> Enum.each(fn media_item ->
|
||||
|
|
@ -110,7 +112,6 @@ defmodule Pinchflat.Sources do
|
|||
end)
|
||||
|
||||
delete_source_metadata_files(source)
|
||||
Tasks.delete_tasks_for(source)
|
||||
Repo.delete(source)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
|||
end
|
||||
|
||||
defp media_center_output_template do
|
||||
"/shows/{{ source_custom_name }}/{{ season_from_date }}/{{ season_episode_from_date }} - {{ title }}.{{ ext }}"
|
||||
"/shows/{{ source_custom_name }}/Season {{ season_from_date }}/{{ season_episode_from_date }} - {{ title }}.{{ ext }}"
|
||||
end
|
||||
|
||||
defp audio_output_template do
|
||||
|
|
|
|||
|
|
@ -95,5 +95,9 @@ defmodule Pinchflat.Downloading.MediaDownloadWorkerTest do
|
|||
|
||||
assert media_item.media_size_bytes > 0
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(MediaDownloadWorker, %{id: 0})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ defmodule Pinchflat.FastIndexing.FastIndexingWorkerTest do
|
|||
expect(HTTPClientMock, :get, fn _url -> {:ok, ""} end)
|
||||
source = source_fixture(fast_index: true)
|
||||
|
||||
perform_job(FastIndexingWorker, %{"id" => source.id})
|
||||
perform_job(FastIndexingWorker, %{id: source.id})
|
||||
end
|
||||
|
||||
test "reschedules itself if fast indexing is enabled" do
|
||||
expect(HTTPClientMock, :get, fn _url -> {:ok, ""} end)
|
||||
source = source_fixture(fast_index: true)
|
||||
perform_job(FastIndexingWorker, %{"id" => source.id})
|
||||
perform_job(FastIndexingWorker, %{id: source.id})
|
||||
|
||||
assert_enqueued(
|
||||
worker: FastIndexingWorker,
|
||||
|
|
@ -50,8 +50,8 @@ defmodule Pinchflat.FastIndexing.FastIndexingWorkerTest do
|
|||
stub(HTTPClientMock, :get, fn _url -> {:ok, ""} end)
|
||||
source = source_fixture(fast_index: true)
|
||||
|
||||
perform_job(FastIndexingWorker, %{"id" => source.id})
|
||||
perform_job(FastIndexingWorker, %{"id" => source.id})
|
||||
perform_job(FastIndexingWorker, %{id: source.id})
|
||||
perform_job(FastIndexingWorker, %{id: source.id})
|
||||
|
||||
assert [_] = all_enqueued(worker: FastIndexingWorker)
|
||||
end
|
||||
|
|
@ -60,14 +60,18 @@ defmodule Pinchflat.FastIndexing.FastIndexingWorkerTest do
|
|||
expect(HTTPClientMock, :get, 0, fn _url -> {:ok, ""} end)
|
||||
source = source_fixture(fast_index: false)
|
||||
|
||||
perform_job(FastIndexingWorker, %{"id" => source.id})
|
||||
perform_job(FastIndexingWorker, %{id: source.id})
|
||||
end
|
||||
|
||||
test "does not reschedule itself if fast indexing is disabled" do
|
||||
source = source_fixture(fast_index: false)
|
||||
perform_job(FastIndexingWorker, %{"id" => source.id})
|
||||
perform_job(FastIndexingWorker, %{id: source.id})
|
||||
|
||||
refute_enqueued(worker: FastIndexingWorker, args: %{"id" => source.id})
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(FastIndexingWorker, %{id: 0})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -53,5 +53,9 @@ defmodule Pinchflat.FastIndexing.MediaIndexingWorkerTest do
|
|||
|
||||
assert [_] = all_enqueued(worker: MediaDownloadWorker)
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(MediaDownloadWorker, %{id: 0, media_url: @media_url})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -74,5 +74,9 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
|||
|
||||
assert [_, _] = all_enqueued(worker: SourceMetadataStorageWorker)
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(SourceMetadataStorageWorker, %{id: 0})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -161,5 +161,9 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do
|
|||
perform_job(MediaCollectionIndexingWorker, %{id: source.id})
|
||||
end)
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(MediaCollectionIndexingWorker, %{id: 0})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue