No site selected

Import Media

Queue cloud-sync handover batches and monitor worker runs.

About this section: Import MediaQueue cloud-sync handover bundles; the worker imports them in the background.

Purpose

Consume the upstream cloud-sync handover bundles from /mnt/ubuntu-nas/node2/assets/sync/ into the global library (asset, asset_gallery, asset_collection) per Decision 639. The CGI never imports inline; it queues batches into import_job for the background worker (Decision 640).

Flow

  • Scan: walks the mount for .ready sentinels and records new ingest_batch rows.
  • Pre-flight: validates the manifest shape, sentinel pair, and per-item decisions; no library writes.
  • Queue: auto-preflights if needed, then inserts an import_job row. Live progress shows on Import Tasks.
  • Bulk queue: select multiple batches and queue them in one click; the worker drains the queue in priority + FIFO order.

Example

Scan finds 37e428d2-a4f6-4a31-bacf-0c835fb24084.ready. Tick its checkbox (or several at once), click Queue selected. The worker claims the next queued job within seconds and writes job_* events as it progresses.

Consequences

  • The library is site-agnostic. Sites surface library content via asset_site_membership, gallery/collection membership, content allowlists, and access packages.
  • VIDEO-SIMPLE syncs import as stable asset_type=video rows with asset_subtype=video_simple, duration, HLS, transcript, cloud-package, and library-cover deliverables.
  • Cancel is allowed only while a job is queued; once running, only systemctl stop gpu-admin-panel-import-worker stops it.
  • Action remove only soft-deletes rows via deleted_at; nothing is hard-deleted.
  • Frosted, blurred, and vivid_blurred derivatives are intentionally not persisted.
Deeper dive

Sourced from gpu-floor/MIGRATION-INTRO.md and the queued-worker decision in DECISION_LOG.md.

Worker contract

A long-running import-worker.pl daemon claims queued jobs using SELECT ... FOR UPDATE SKIP LOCKED (MariaDB 10.6+). It updates heartbeat_at every few items; if a worker dies, its running jobs are reset to queued after the configured stale threshold (default 15 minutes).

Sentinel protocol

A bundle is consumable only when both <sync_id>.json and <sync_id>.ready exist and the JSON has status = completed and verification.passed = true. The importer recomputes manifest_sha256 at consumption time so audit history records what we actually ingested.

Source-of-truth mapping

  • source/source.json -> asset_source (cold provenance).
  • source/data/photo.manifest.json + photo.analysis.json + photo.meaning.json + photo.family.json -> asset_ai_run rows with explicit analysis_kind; unknown filenames are captured with source_data:<file>.
  • Bundled cover_hash -> asset_cover linked to the parent asset.
  • Containers of type gallery -> asset_gallery + asset_gallery_item junctions.

Idempotency + integrity

Every multi-row write is wrapped in AdminDB::transaction. Hash-based UNIQUE keys make re-running the same batch a no-op. Per-item failures isolate to ingest_batch_item.decision = failed with last_error; the batch becomes partial when any siblings still succeeded.

Read-only mount + ledger boundary

The /mnt/ubuntu-nas/node2/assets tree is read-only for admin consumers. The importer never writes to upstream or deletes .ready sentinels; all consumer state lives in ingest_batch / ingest_batch_item / ingest_event / import_job in admin_panel.

Batch cf572e43-bed5-4d97-9aaf-9669a019647d

Status: imported; action: import

Type

asset

Action

import

Status

imported

Items

3

Bytes

209.3 MB

Source host

orbit-2

Manifest sha256

f26aee97b747d13f...

Started

2026-07-08 18:19:18

Completed

2026-07-08 18:20:20

Manifest summary

  • created_at: 2026-07-08T18:15:32Z
  • completed_at: 2026-07-08T18:15:32Z
  • verification.passed: true
  • verification.total_files: 461
  • prior_sync_id: none

Job history 1

Newest first. The active job (if any) is at the top.

idstaterequested_byqueuedclaimedworkerprogressfinishedlast_error
101doneimport-feed2026-07-08 18:19:202026-07-08 18:19:23vultr/pid:2549543/32026-07-08 18:20:20-

Items 3

Per-item decisions captured by preflight and updated by import. Re-running pre-flight is safe.

asset_typeasset_hashcover_hashdecisiontarget idslast_errorupdated_at
reel343664556e2f143f...e41d6d2774a44fd8...createdasset:13542-2026-07-08 18:19:45
reel282e770091f9ec22...7f3e5ce5a9594b3a...createdasset:13543-2026-07-08 18:20:04
reel3b5d7a8344b538d9...82a2a93810514120...createdasset:13544-2026-07-08 18:20:20

Recent events

Append-only audit ledger for this batch (latest 50).

event_typepayloadcreated_at
job_finished{"error":null,"job_id":"101","phase":"job_finish","summary":{"items_seen":3,"ok":1,"status":"imported","summary":{"ok":1,"remaining":0,"status":"imported","tally":{"created":3,"deferred":0,"failed":0,...2026-07-08 18:20:20
import_finished{"phase":"import","remaining":0,"skipped_terminal":0,"status":"imported","tally":{"created":3,"deferred":0,"failed":0,"linked":0,"skipped":0,"updated":0}}2026-07-08 18:20:20
item_created{"cover_hash":"82a2a93810514120b1aecf35cbe4e9f2","error":null,"hash":"3b5d7a8344b538d9a43539842426604d","phase":"item_import","target_ids":{"asset_id":"13544"},"type":"reel"}2026-07-08 18:20:20
item_created{"cover_hash":"7f3e5ce5a9594b3aba76a6f412ddc82a","error":null,"hash":"282e770091f9ec227fb91544517b7580","phase":"item_import","target_ids":{"asset_id":"13543"},"type":"reel"}2026-07-08 18:20:04
item_created{"cover_hash":"e41d6d2774a44fd8af440655e62798de","error":null,"hash":"343664556e2f143f02abb417ed11a814","phase":"item_import","target_ids":{"asset_id":"13542"},"type":"reel"}2026-07-08 18:19:45
import_started{"action":"import","already_terminal_count":0,"container_count":1,"item_count":3,"manifest_sha256":"f26aee97b747d13fc6716df91267ea4253bc09fc9c4517d0b59030f1d9bbd71c","max_items":0,"phase":"import"}2026-07-08 18:19:27
job_claimed{"job_id":"101","phase":"job_claim","priority":100,"worker_id":"vultr/pid:254954"}2026-07-08 18:19:23
job_queued{"job_id": "101", "requested_by": "import-feed", "items_total": "3"}2026-07-08 18:19:20
preflight_finished{"counts":{"will_create":3,"will_fail":0,"will_link":0,"will_skip":0,"will_update":0},"failure_samples":[],"item_count":3,"item_type_counts":{"reel":3},"ok":1,"phase":"preflight"}2026-07-08 18:19:20
preflight_started{"action":"import","container_count":1,"item_count":3,"item_type_counts":{"reel":3},"manifest_sha256":"f26aee97b747d13fc6716df91267ea4253bc09fc9c4517d0b59030f1d9bbd71c","phase":"preflight","shape_erro...2026-07-08 18:19:18
scan{"source": "import-feed", "manifest_sha256": "f26aee97b747d13fc6716df91267ea4253bc09fc9c4517d0b59030f1d9bbd71c", "sync_type": "asset", "action": "import", "item_count": "3"}2026-07-08 18:19:18