Removed unused backfill worker
This commit is contained in:
parent
0c4166973c
commit
15b6b5db30
3 changed files with 1 additions and 121 deletions
|
|
@ -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
|
|
||||||
|
|
@ -11,9 +11,6 @@ defmodule Pinchflat.Boot.PostJobStartupTasks do
|
||||||
use GenServer, restart: :temporary
|
use GenServer, restart: :temporary
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
|
|
||||||
alias Pinchflat.Repo
|
|
||||||
alias Pinchflat.Boot.DataBackfillWorker
|
|
||||||
|
|
||||||
def start_link(opts \\ []) do
|
def start_link(opts \\ []) do
|
||||||
GenServer.start_link(__MODULE__, %{}, opts)
|
GenServer.start_link(__MODULE__, %{}, opts)
|
||||||
end
|
end
|
||||||
|
|
@ -29,16 +26,7 @@ defmodule Pinchflat.Boot.PostJobStartupTasks do
|
||||||
"""
|
"""
|
||||||
@impl true
|
@impl true
|
||||||
def init(state) do
|
def init(state) do
|
||||||
enqueue_backfill_worker()
|
# Empty for now, keeping because tasks _will_ be added in future
|
||||||
|
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp enqueue_backfill_worker do
|
|
||||||
DataBackfillWorker.cancel_pending_backfill_jobs()
|
|
||||||
|
|
||||||
%{}
|
|
||||||
|> DataBackfillWorker.new()
|
|
||||||
|> Repo.insert_unique_job()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Reference in a new issue