importer

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package importer runs the post-download pipeline: find media file, apply naming template, transfer to library, update DB, refresh media servers. Fed by internal/jobs/download_monitor (event-fast path) and by the import_scan scheduler job (restart-safe path).

Index

Constants

This section is empty.

Variables

View Source
var ErrPathNotAllowed = errors.New("save_path not in allowed download roots")

ErrPathNotAllowed is returned when a DownloadRecord.save_path is not within any configured Library.AllowedDownloadRoots prefix.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	DB          db.Store
	Library     *library.ImportService
	Download    download.Downloader
	MediaServer MediaServerDispatcher
}

Deps is worker wiring. User-facing knobs (max attempts, keep seeding, allowed roots, movie library path) are read via config.Get() inside runImport.

type Enqueuer

type Enqueuer interface {
	Enqueue(recordID uint32)
}

Enqueuer is the consumer-facing queue surface. download_monitor accepts it so it can be driven by a fake in tests without pulling in the full Worker.

type MediaServerDispatcher

type MediaServerDispatcher interface {
	RefreshAll(ctx context.Context, libraryPath string) error
}

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(d Deps) *Worker

func (*Worker) Enqueue

func (w *Worker) Enqueue(recordID uint32)

Enqueue pushes a record ID into the import queue. Non-blocking: when the queue is full the ID is dropped (import_scan will pick it up on the next tick). Dedupe: IDs already in-flight are dropped. After shutdown every enqueue is dropped — nothing is left to consume the queue.

func (*Worker) Scan

func (w *Worker) Scan(ctx context.Context) error

Scan re-enqueues all DownloadRecords sitting at status=importing. Used by the scheduler as a safety net after a restart or a dropped enqueue.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context)

Start spawns consumer goroutines reading from the queue. Blocks until ctx is canceled and every consumer has finished its current import. Safe to call once per app lifetime.

w.ch is deliberately never closed: scheduler jobs holding this worker as an importer.Enqueuer keep calling Enqueue after ctx is canceled, and a send on a closed channel would panic them. Consumers terminate on ctx.Done instead; w.stop turns those late enqueues into no-ops.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL