bdef6c75bb
* Ensure channel detail lookup doesn't download the video - oops * Ran the needful migrations for replacing channels with sources * got media source test back working * channel tasks test * Media indexing worker test * media tests * Got all tests working except controller tests * got all tests working * Renamed Channel struct to Source * renamed ChannelTasks * More renaming; renamed channel details module * Removed Channel yt-dlp module, instead throwing things in the VideoCollection module * Renamed what looks like the last of the outstanding data
34 lines
995 B
Elixir
34 lines
995 B
Elixir
defmodule Pinchflat.Tasks.SourceTasks do
|
|
@moduledoc """
|
|
This module contains methods for managing tasks (workers) related to sources.
|
|
"""
|
|
|
|
alias Pinchflat.Tasks
|
|
alias Pinchflat.MediaSource.Source
|
|
alias Pinchflat.Workers.MediaIndexingWorker
|
|
|
|
@doc """
|
|
Starts tasks for indexing a source's media.
|
|
|
|
Returns {:ok, :should_not_index} | {:ok, %Task{}}.
|
|
"""
|
|
def kickoff_indexing_task(%Source{} = source) do
|
|
Tasks.delete_pending_tasks_for(source)
|
|
|
|
if source.index_frequency_minutes <= 0 do
|
|
{:ok, :should_not_index}
|
|
else
|
|
source
|
|
|> Map.take([:id])
|
|
# Schedule this one immediately, but future ones will be on an interval
|
|
|> MediaIndexingWorker.new()
|
|
|> Tasks.create_job_with_task(source)
|
|
|> case do
|
|
# This should never return {:error, :duplicate_job} since we just deleted
|
|
# any pending tasks. I'm being assertive about it so it's obvious if I'm wrong
|
|
{:ok, task} -> {:ok, task}
|
|
end
|
|
end
|
|
end
|
|
end
|