diff --git a/lib/pinchflat/boot/data_backfill_worker.ex b/lib/pinchflat/boot/data_backfill_worker.ex deleted file mode 100644 index 37cd946..0000000 --- a/lib/pinchflat/boot/data_backfill_worker.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule Pinchflat.Boot.DataBackfillWorker do - @moduledoc false - - use Oban.Worker, - queue: :local_metadata, - unique: [period: :infinity, states: [:available, :scheduled, :retryable]], - tags: ["media_item", "media_metadata", "local_metadata", "data_backfill"] - - # This one is going to be a little more self-contained - # instead of relying on outside modules for the methods. - # That's because, for now, these methods are not intended - # to be used elsewhere. - # - # I'm just trying out that pattern and seeing if I like it better - # so this may change. - import Ecto.Query, warn: false - require Logger - - alias __MODULE__ - alias Pinchflat.Repo - - @doc """ - Cancels all pending backfill jobs. Useful for ensuring worker runs immediately - on app boot. - - Returns {:ok, integer()} - """ - def cancel_pending_backfill_jobs do - Oban.Job - |> where(worker: "Pinchflat.Boot.DataBackfillWorker") - |> Oban.cancel_all_jobs() - end - - @impl Oban.Worker - @doc """ - Performs one-off tasks to get data in the right shape. - This can be needed when we add new features or change the way - we store data. Must be idempotent. All new data should already - conform to the expected schema so this should only be needed - for existing data. Still runs periodically to be safe. - - Returns :ok - """ - def perform(%Oban.Job{}) do - Logger.info("Running data backfill worker") - # Nothing to do for now - just reschedule - # Keeping in-place because we _will_ need it in the future - - reschedule_backfill() - - :ok - end - - defp reschedule_backfill do - # Run hourly - next_run_in = 60 * 60 - - %{} - |> DataBackfillWorker.new(schedule_in: next_run_in) - |> Repo.insert_unique_job() - end -end diff --git a/lib/pinchflat/boot/post_job_startup_tasks.ex b/lib/pinchflat/boot/post_job_startup_tasks.ex index 4d11159..867c300 100644 --- a/lib/pinchflat/boot/post_job_startup_tasks.ex +++ b/lib/pinchflat/boot/post_job_startup_tasks.ex @@ -11,9 +11,6 @@ defmodule Pinchflat.Boot.PostJobStartupTasks do use GenServer, restart: :temporary import Ecto.Query, warn: false - alias Pinchflat.Repo - alias Pinchflat.Boot.DataBackfillWorker - def start_link(opts \\ []) do GenServer.start_link(__MODULE__, %{}, opts) end @@ -29,16 +26,7 @@ defmodule Pinchflat.Boot.PostJobStartupTasks do """ @impl true def init(state) do - enqueue_backfill_worker() - + # Empty for now, keeping because tasks _will_ be added in future {:ok, state} end - - defp enqueue_backfill_worker do - DataBackfillWorker.cancel_pending_backfill_jobs() - - %{} - |> DataBackfillWorker.new() - |> Repo.insert_unique_job() - end end diff --git a/test/pinchflat/boot/data_backfill_worker_test.exs b/test/pinchflat/boot/data_backfill_worker_test.exs deleted file mode 100644 index 485f281..0000000 --- a/test/pinchflat/boot/data_backfill_worker_test.exs +++ /dev/null @@ -1,46 +0,0 @@ -defmodule Pinchflat.Boot.DataBackfillWorkerTest do - use Pinchflat.DataCase - - alias Pinchflat.Boot.DataBackfillWorker - alias Pinchflat.JobFixtures.TestJobWorker - - describe "cancel_pending_backfill_jobs/0" do - test "cancels all pending backfill jobs" do - %{} - |> DataBackfillWorker.new() - |> Repo.insert_unique_job() - - assert_enqueued(worker: DataBackfillWorker) - - DataBackfillWorker.cancel_pending_backfill_jobs() - - refute_enqueued(worker: DataBackfillWorker) - end - - test "does not cancel jobs for other workers" do - %{id: 0} - |> TestJobWorker.new() - |> Repo.insert_unique_job() - - assert_enqueued(worker: TestJobWorker) - - DataBackfillWorker.cancel_pending_backfill_jobs() - - assert_enqueued(worker: TestJobWorker) - end - end - - describe "perform/1" do - setup do - DataBackfillWorker.cancel_pending_backfill_jobs() - - :ok - end - - test "reschedules itself once complete" do - perform_job(DataBackfillWorker, %{}) - - assert_enqueued(worker: DataBackfillWorker, scheduled_at: now_plus(60, :minutes)) - end - end -end