Refactors
This commit is contained in:
parent
3c15884bf3
commit
9590fd1a98
3 changed files with 26 additions and 8 deletions
|
|
@ -201,8 +201,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
|
||||||
archive_contents =
|
archive_contents =
|
||||||
source
|
source
|
||||||
|> get_media_items_for_download_archive()
|
|> get_media_items_for_download_archive()
|
||||||
|> Enum.map(fn media_item -> "youtube #{media_item.media_id}" end)
|
|> Enum.map_join("\n", fn media_item -> "youtube #{media_item.media_id}" end)
|
||||||
|> Enum.join("\n")
|
|
||||||
|
|
||||||
case File.write(tmpfile, archive_contents) do
|
case File.write(tmpfile, archive_contents) do
|
||||||
:ok -> tmpfile
|
:ok -> tmpfile
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,21 @@ defmodule Pinchflat.Utils.FilesystemUtils do
|
||||||
|
|
||||||
Returns binary()
|
Returns binary()
|
||||||
"""
|
"""
|
||||||
# TODO: consider namespacing these folders like they do in activestorage
|
|
||||||
def generate_metadata_tmpfile(type) do
|
def generate_metadata_tmpfile(type) do
|
||||||
|
filename = StringUtils.random_string(64)
|
||||||
|
# This "namespacing" is more to help with development since things get
|
||||||
|
# weird in my editor when there are thousands of files in a single directory
|
||||||
|
first_two = String.slice(filename, 0..1)
|
||||||
|
second_two = String.slice(filename, 2..3)
|
||||||
tmpfile_directory = Application.get_env(:pinchflat, :tmpfile_directory)
|
tmpfile_directory = Application.get_env(:pinchflat, :tmpfile_directory)
|
||||||
filepath = Path.join([tmpfile_directory, "#{StringUtils.random_string(64)}.#{type}"])
|
|
||||||
|
filepath =
|
||||||
|
Path.join([
|
||||||
|
tmpfile_directory,
|
||||||
|
first_two,
|
||||||
|
second_two,
|
||||||
|
"#{filename}.#{type}"
|
||||||
|
])
|
||||||
|
|
||||||
:ok = write_p!(filepath, "")
|
:ok = write_p!(filepath, "")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,16 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do
|
||||||
describe "perform/1" do
|
describe "perform/1" do
|
||||||
setup do
|
setup do
|
||||||
stub(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end)
|
stub(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end)
|
||||||
|
|
||||||
stub(AppriseRunnerMock, :run, fn _, _ -> {:ok, ""} end)
|
stub(AppriseRunnerMock, :run, fn _, _ -> {:ok, ""} end)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
test "indexes the source if it should be indexed" do
|
test "indexes the source if it should be indexed" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end)
|
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts ->
|
||||||
|
{:ok, ""}
|
||||||
|
end)
|
||||||
|
|
||||||
source = source_fixture(index_frequency_minutes: 10)
|
source = source_fixture(index_frequency_minutes: 10)
|
||||||
|
|
||||||
|
|
@ -65,7 +68,9 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "indexes the source no matter what if the source has never been indexed before" do
|
test "indexes the source no matter what if the source has never been indexed before" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end)
|
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts ->
|
||||||
|
{:ok, ""}
|
||||||
|
end)
|
||||||
|
|
||||||
source = source_fixture(index_frequency_minutes: 0, last_indexed_at: nil)
|
source = source_fixture(index_frequency_minutes: 0, last_indexed_at: nil)
|
||||||
|
|
||||||
|
|
@ -73,7 +78,9 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "indexes the source no matter what if the 'force' arg is passed" do
|
test "indexes the source no matter what if the 'force' arg is passed" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end)
|
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts ->
|
||||||
|
{:ok, ""}
|
||||||
|
end)
|
||||||
|
|
||||||
source = source_fixture(index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now())
|
source = source_fixture(index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now())
|
||||||
|
|
||||||
|
|
@ -88,7 +95,8 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
source = source_fixture(collection_type: :channel, index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now())
|
source =
|
||||||
|
source_fixture(collection_type: :channel, index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now())
|
||||||
|
|
||||||
perform_job(MediaCollectionIndexingWorker, %{id: source.id, force: true})
|
perform_job(MediaCollectionIndexingWorker, %{id: source.id, force: true})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue