channel tasks test
This commit is contained in:
parent
d54f9f8a79
commit
bbae39b523
2 changed files with 15 additions and 15 deletions
|
|
@ -8,21 +8,21 @@ defmodule Pinchflat.Tasks.ChannelTasks do
|
|||
alias Pinchflat.Workers.MediaIndexingWorker
|
||||
|
||||
@doc """
|
||||
Starts tasks for indexing a channel's media.
|
||||
Starts tasks for indexing a source's media.
|
||||
|
||||
Returns {:ok, :should_not_index} | {:ok, %Task{}}.
|
||||
"""
|
||||
def kickoff_indexing_task(%Channel{} = channel) do
|
||||
Tasks.delete_pending_tasks_for(channel)
|
||||
def kickoff_indexing_task(%Channel{} = source) do
|
||||
Tasks.delete_pending_tasks_for(source)
|
||||
|
||||
if channel.index_frequency_minutes <= 0 do
|
||||
if source.index_frequency_minutes <= 0 do
|
||||
{:ok, :should_not_index}
|
||||
else
|
||||
channel
|
||||
source
|
||||
|> Map.take([:id])
|
||||
# Schedule this one immediately, but future ones will be on an interval
|
||||
|> MediaIndexingWorker.new()
|
||||
|> Tasks.create_job_with_task(channel)
|
||||
|> 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
|
||||
|
|
|
|||
|
|
@ -12,32 +12,32 @@ defmodule Pinchflat.Tasks.ChannelTasksTest do
|
|||
test "it does not schedule a job if the interval is <= 0" do
|
||||
source = source_fixture(index_frequency_minutes: -1)
|
||||
|
||||
assert {:ok, :should_not_index} = ChannelTasks.kickoff_indexing_task(channel)
|
||||
assert {:ok, :should_not_index} = ChannelTasks.kickoff_indexing_task(source)
|
||||
|
||||
refute_enqueued(worker: MediaIndexingWorker, args: %{"id" => channel.id})
|
||||
refute_enqueued(worker: MediaIndexingWorker, args: %{"id" => source.id})
|
||||
end
|
||||
|
||||
test "it schedules a job if the interval is > 0" do
|
||||
source = source_fixture(index_frequency_minutes: 1)
|
||||
|
||||
assert {:ok, _} = ChannelTasks.kickoff_indexing_task(channel)
|
||||
assert {:ok, _} = ChannelTasks.kickoff_indexing_task(source)
|
||||
|
||||
assert_enqueued(worker: MediaIndexingWorker, args: %{"id" => channel.id})
|
||||
assert_enqueued(worker: MediaIndexingWorker, args: %{"id" => source.id})
|
||||
end
|
||||
|
||||
test "it creates and attaches a task if the interval is > 0" do
|
||||
source = source_fixture(index_frequency_minutes: 1)
|
||||
|
||||
assert {:ok, %Task{} = task} = ChannelTasks.kickoff_indexing_task(channel)
|
||||
assert {:ok, %Task{} = task} = ChannelTasks.kickoff_indexing_task(source)
|
||||
|
||||
assert task.channel_id == channel.id
|
||||
assert task.source_id == source.id
|
||||
end
|
||||
|
||||
test "it deletes any pending tasks for the channel" do
|
||||
test "it deletes any pending tasks for the source" do
|
||||
source = source_fixture()
|
||||
task = task_fixture(channel_id: channel.id)
|
||||
task = task_fixture(source_id: source.id)
|
||||
|
||||
assert {:ok, _} = ChannelTasks.kickoff_indexing_task(channel)
|
||||
assert {:ok, _} = ChannelTasks.kickoff_indexing_task(source)
|
||||
|
||||
assert_raise Ecto.NoResultsError, fn -> Repo.reload!(task) end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue