PhoenixKit.Modules.Storage.Workers.ReconcileJob (phoenix_kit v2.41.0)

Copy Markdown View Source

Runs PhoenixKit.Modules.Storage.Reconciler over the stale files (V205): copies objects where a library's storage profile wants them, unlinks them where it no longer does, and makes, remakes or deletes sizes by its variant set.

Throttled, like the location backfill: @batch_size files per run, the next run @pause_seconds later, on the file_processing queue, so its copying and its ImageMagick/FFmpeg work stay bounded by that queue. Only one pending run exists at a time (unique over [:worker, :queue], ignoring the cursor): a change queued while a pass is under way starts the walk again from the beginning (a waiting next batch is replaced). A file that could not be finished waits ten minutes before it is tried again (reconcile_attempted_at), so a restart does not retry the same failing files ahead of the rest.

Queued by itself (enqueue/0): whenever a profile, a variant set or one of their rows changes (their revision is bumped), a library moves to another profile or set, an upload makes fewer copies or sizes than wanted, and by the daily trash prune and on boot while any file is stale. It never waits for a person; the Health page shows what is left.

It replaces SyncFilesJob, the Health page's manual sync.

Summary

Functions

Queues a pass from the beginning. Never raises: a change must not fail because Oban is not running (a test, a Mix task); the daily prune and the next boot queue one anyway.

Queues a pass when any file is stale. Never raises.

Runs a whole pass in the calling process and returns the totals (:reconciled, :stale, :skipped). For tests and Mix tasks.

Functions

enqueue()

@spec enqueue() :: :queued | :unavailable

Queues a pass from the beginning. Never raises: a change must not fail because Oban is not running (a test, a Mix task); the daily prune and the next boot queue one anyway.

maybe_enqueue()

@spec maybe_enqueue() :: :queued | :nothing_to_do | :unavailable

Queues a pass when any file is stale. Never raises.

run_pass()

@spec run_pass() :: map()

Runs a whole pass in the calling process and returns the totals (:reconciled, :stale, :skipped). For tests and Mix tasks.