PhoenixKit.Modules.Storage.Jobs.Reconcile (phoenix_kit v2.52.2)

Copy Markdown View Source

Brings one library's files up to date with its storage profile and variant set (storage.reconcile, V205): copies objects where the profile wants them, unlinks them where it no longer does, and makes, remakes or deletes sizes by the set. PhoenixKit.Modules.Storage.Reconciler does the work of a batch.

One run per library (scope {"library", uuid}). That is what lets an admin see a library's state, check it, pause it and read who did what (dev_docs/plans/2026-10-03-job-runs.md, §6.2). A run with no library scope walks every library, as the old pass did.

Started by itself — trigger/1 starts a run for each library that has files the reconciler may take, whenever a profile, a variant set or one of their rows changes (their revision is bumped), a library moves to another one, an upload made fewer copies or sizes than wanted, and by the daily prune and on boot. It is called by Storage.Workers.ReconcileJob, the Oban job those places have always queued (so they work inside a transaction too, and an older job still in the queue does the right thing). An admin starts one with Check now.

restart/0 is :restart: a change made while a pass runs starts the pass again from the beginning at its next batch boundary, because its cursor would skip files the change made stale.

Throttled: ten files a batch, two seconds between batches, on the file_processing queue, so copying and ImageMagick/FFmpeg work stay bounded by that queue. A file that could not be finished waits ten minutes before it is tried again (reconcile_attempted_at).

Counts. done is files reconciled, failed files that could not be finished yet (they stay stale), total the files this pass starts with. A pass whose batch was interrupted counts that batch's already-finished files in nobody's tally (see PhoenixKit.Jobs.Kind).

Summary

Functions

Starts a run for every library that has files the reconciler may take now, and records a restart for existing library runs even when their files are temporarily ineligible or their current batch has already stamped them. Returns {:ok, libraries} or {:error, reason} if a start was refused. A database error raises; the trigger job retries either failure.

Functions

trigger(opts \\ [])

@spec trigger(keyword()) :: {:ok, [String.t()]} | {:error, term()}

Starts a run for every library that has files the reconciler may take now, and records a restart for existing library runs even when their files are temporarily ineligible or their current batch has already stamped them. Returns {:ok, libraries} or {:error, reason} if a start was refused. A database error raises; the trigger job retries either failure.

:source is the short phrase the run's history keeps ("a profile changed").