worker

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidScanOptions = errors.New("exactly one of FilePath, FileID, or BookID must be set")

ErrInvalidScanOptions is returned when ScanOptions validation fails.

Functions

This section is empty.

Types

type ScanOptions

type ScanOptions struct {
	// Entry points (mutually exclusive - exactly one must be set)
	FilePath string // Batch scan: discover/create by path
	FileID   int    // Single file resync: file already in DB
	BookID   int    // Book resync: scan all files in book

	// Context (required for FilePath mode)
	LibraryID int

	// Behavior
	ForceRefresh bool // Bypass priority checks, overwrite all metadata

	// Logging (optional, for batch scan job context)
	JobLog *joblogs.JobLogger
}

ScanOptions configures a scan operation.

Entry points are mutually exclusive - exactly one of FilePath, FileID, or BookID must be set:

  • FilePath: Batch scan mode - discover or create file/book records by path. Requires LibraryID to be set.
  • FileID: Single file resync - file already exists in DB. If the file no longer exists on disk, it will be deleted from the database.
  • BookID: Book resync - scan all files belonging to the book. If the book has no files, it will be deleted.

type ScanResult

type ScanResult struct {
	// For single file scans
	File        *models.File // The scanned/updated file (nil if deleted)
	Book        *models.Book // The parent book (nil if deleted)
	FileCreated bool         // True if file was newly created (FilePath mode only)
	FileDeleted bool         // True if file was deleted (no longer on disk)
	BookDeleted bool         // True if book was also deleted (was last file)

	// For book scans (multiple files)
	Files []*ScanResult // Results for each file in the book (BookID mode only)
}

ScanResult contains the results of a scan operation.

For single file scans (FilePath or FileID mode), the File and Book fields contain the scanned/updated records. FileCreated indicates whether a new file record was created (only possible in FilePath mode). FileDeleted and BookDeleted indicate whether records were removed because the file no longer exists on disk.

For book scans (BookID mode), the Files slice contains the results for each individual file in the book. The top-level Book field contains the updated book record (unless BookDeleted is true).

type Worker

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

func New

func New(cfg *config.Config, db *bun.DB, pm *plugins.Manager) *Worker

func (*Worker) ProcessScanJob

func (w *Worker) ProcessScanJob(ctx context.Context, job *models.Job, jobLog *joblogs.JobLogger) error

func (*Worker) Scan

func (w *Worker) Scan(ctx context.Context, opts books.ScanOptions) (*books.ScanResult, error)

Scan implements the books.Scanner interface. It converts books.ScanOptions to worker.ScanOptions, calls the internal scanInternal method, and converts the result back to books.ScanResult.

func (*Worker) Shutdown

func (w *Worker) Shutdown()

func (*Worker) Start

func (w *Worker) Start()

Jump to

Keyboard shortcuts

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