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 ¶
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 Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
func (*Worker) Enqueue ¶
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 ¶
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 ¶
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.