[WIP] added delay between indexing and downloading in some cases
This commit is contained in:
parent
1305a485a0
commit
5d624f545b
3 changed files with 23 additions and 8 deletions
|
|
@ -27,13 +27,19 @@ defmodule Pinchflat.Downloading.DownloadingHelpers do
|
||||||
|
|
||||||
Returns :ok
|
Returns :ok
|
||||||
"""
|
"""
|
||||||
def enqueue_pending_download_tasks(%Source{download_media: true} = source) do
|
def enqueue_pending_download_tasks(source, opts \\ [])
|
||||||
|
|
||||||
|
def enqueue_pending_download_tasks(%Source{download_media: true} = source, opts) do
|
||||||
|
# TODO: test
|
||||||
|
# TODO: doc
|
||||||
|
kickoff_delay = Keyword.get(opts, :kickoff_delay, 0)
|
||||||
|
|
||||||
source
|
source
|
||||||
|> Media.list_pending_media_items_for()
|
|> Media.list_pending_media_items_for()
|
||||||
|> Enum.each(&MediaDownloadWorker.kickoff_with_task/1)
|
|> Enum.each(&MediaDownloadWorker.kickoff_with_task(&1, %{}, schedule_in: kickoff_delay))
|
||||||
end
|
end
|
||||||
|
|
||||||
def enqueue_pending_download_tasks(%Source{download_media: false}) do
|
def enqueue_pending_download_tasks(%Source{download_media: false}, _opts) do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -55,13 +61,16 @@ defmodule Pinchflat.Downloading.DownloadingHelpers do
|
||||||
|
|
||||||
Returns {:ok, %Task{}} | {:error, :should_not_download} | {:error, any()}
|
Returns {:ok, %Task{}} | {:error, :should_not_download} | {:error, any()}
|
||||||
"""
|
"""
|
||||||
def kickoff_download_if_pending(%MediaItem{} = media_item) do
|
def kickoff_download_if_pending(%MediaItem{} = media_item, opts \\ []) do
|
||||||
|
# TODO: test
|
||||||
|
# TODO: doc
|
||||||
|
kickoff_delay = Keyword.get(opts, :kickoff_delay, 0)
|
||||||
media_item = Repo.preload(media_item, :source)
|
media_item = Repo.preload(media_item, :source)
|
||||||
|
|
||||||
if media_item.source.download_media && Media.pending_download?(media_item) do
|
if media_item.source.download_media && Media.pending_download?(media_item) do
|
||||||
Logger.info("Kicking off download for media item ##{media_item.id} (#{media_item.media_id})")
|
Logger.info("Kicking off download for media item ##{media_item.id} (#{media_item.media_id})")
|
||||||
|
|
||||||
MediaDownloadWorker.kickoff_with_task(media_item)
|
MediaDownloadWorker.kickoff_with_task(media_item, %{}, schedule_in: kickoff_delay)
|
||||||
else
|
else
|
||||||
{:error, :should_not_download}
|
{:error, :should_not_download}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,9 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpers do
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
DownloadingHelpers.enqueue_pending_download_tasks(source)
|
# Wait 5s before enqueuing downloads to give the post-indexing user script a chance to run
|
||||||
|
# TODO: test
|
||||||
|
DownloadingHelpers.enqueue_pending_download_tasks(source, kickoff_delay: 5)
|
||||||
|
|
||||||
Enum.filter(maybe_new_media_items, & &1)
|
Enum.filter(maybe_new_media_items, & &1)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Sources.update_source(source, %{last_indexed_at: DateTime.utc_now()})
|
Sources.update_source(source, %{last_indexed_at: DateTime.utc_now()})
|
||||||
DownloadingHelpers.enqueue_pending_download_tasks(source)
|
# Wait 5s before enqueuing downloads to give the post-indexing user script a chance to run
|
||||||
|
# TODO: test
|
||||||
|
DownloadingHelpers.enqueue_pending_download_tasks(source, kickoff_delay: 5)
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
@ -125,7 +127,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
|
||||||
|
|
||||||
case Media.create_media_item_from_backend_attrs(source, media_attrs) do
|
case Media.create_media_item_from_backend_attrs(source, media_attrs) do
|
||||||
{:ok, %MediaItem{} = media_item} ->
|
{:ok, %MediaItem{} = media_item} ->
|
||||||
DownloadingHelpers.kickoff_download_if_pending(media_item)
|
# Wait 5s before enqueuing downloads to give the post-indexing user script a chance to run
|
||||||
|
# TODO: test
|
||||||
|
DownloadingHelpers.kickoff_download_if_pending(media_item, kickoff_delay: 5)
|
||||||
|
|
||||||
{:error, changeset} ->
|
{:error, changeset} ->
|
||||||
changeset
|
changeset
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue