From da1fd98e83003516c759468051b5d79c6ca60792 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 25 Jan 2024 08:53:29 -0800 Subject: [PATCH] Added basic Oban job for indexing --- config/config.exs | 3 ++- lib/pinchflat/workers/media_indexing_worker.ex | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lib/pinchflat/workers/media_indexing_worker.ex diff --git a/config/config.exs b/config/config.exs index 60b1bca..13647a2 100644 --- a/config/config.exs +++ b/config/config.exs @@ -30,7 +30,8 @@ config :pinchflat, PinchflatWeb.Endpoint, config :pinchflat, Oban, repo: Pinchflat.Repo, plugins: [Oban.Plugins.Pruner], - queues: [default: 10] + # TODO: consider making this an env var or something? + queues: [default: 10, media_indexing: 2, media_fetching: 2] # Configures the mailer # diff --git a/lib/pinchflat/workers/media_indexing_worker.ex b/lib/pinchflat/workers/media_indexing_worker.ex new file mode 100644 index 0000000..01bed11 --- /dev/null +++ b/lib/pinchflat/workers/media_indexing_worker.ex @@ -0,0 +1,17 @@ +defmodule Pinchflat.Workers.MediaIndexingWorker do + use Oban.Worker, queue: :media_indexing + + alias Pinchflat.MediaSource + + @impl Oban.Worker + # This `channel_id` is the ID of the channel _record_ in + # the database, not the ID of the channel on YouTube. + # TODO: test + def perform(%Oban.Job{args: %{"channel_id" => channel_id}}) do + channel_id + |> MediaSource.get_channel!() + |> MediaSource.index_media_items() + + :ok + end +end