jobs

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package jobs provides background job execution functionality.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidStreamPort = errors.New("invalid stream port")

ErrInvalidStreamPort marks an invalid stream port configuration.

Functions

This section is empty.

Types

type Artifacts added in v1.7.0

type Artifacts struct {
	Bouquets      map[string]string // Bouquet name -> reference
	Services      [][]string        // Raw services from OpenWebIF
	PlaylistItems []playlist.Item   // Processed playlist items
	EPGProgrammes int               // Number of EPG programmes collected
	Stats         RefreshStats
}

Artifacts represents the output of a refresh operation

type Config

type Config struct {
	Version       string
	DataDir       string
	OWIBase       string
	OWIUsername   string // Optional: HTTP Basic Auth username
	OWIPassword   string // Optional: HTTP Basic Auth password
	Bouquet       string // Comma-separated list of bouquets (e.g., "Premium,Favourites")
	XMLTVPath     string
	PiconBase     string
	FuzzyMax      int
	StreamPort    int
	APIToken      string // Optional: for securing the /api/refresh endpoint
	OWITimeout    time.Duration
	OWIRetries    int
	OWIBackoff    time.Duration
	OWIMaxBackoff time.Duration

	// EPG Configuration
	EPGEnabled        bool
	EPGDays           int    // Number of days to fetch EPG data (1-14)
	EPGMaxConcurrency int    // Max parallel EPG requests (1-10)
	EPGTimeoutMS      int    // Timeout per EPG request in milliseconds
	EPGRetries        int    // Retry attempts for EPG requests
	EPGSource         string // EPG fetch strategy: "bouquet" (fast, single request) or "per-service" (default, per-channel requests)
}

Config holds configuration for refresh operations

type Deps added in v1.7.0

type Deps struct {
	Logger      Logger
	Config      Config
	Client      OpenWebIFClient
	Metrics     MetricsRecorder
	FileWriter  FileWriter
	Clock       func() time.Time
	Parallelism int // Max parallel EPG fetches
}

Deps holds all dependencies for the refresh operation

type FileWriter added in v1.7.0

type FileWriter interface {
	WriteAtomic(ctx context.Context, path string, data []byte) error
}

FileWriter defines the interface for writing files atomically

type Logger added in v1.7.0

type Logger interface {
	Info() *zerolog.Event
	Warn() *zerolog.Event
	Error() *zerolog.Event
	Debug() *zerolog.Event
}

Logger defines the logging interface for refresh operations

type MetricsRecorder added in v1.7.0

type MetricsRecorder interface {
	RecordBouquetsCount(count int)
	RecordServicesCount(bouquet string, count int)
	RecordChannelTypeCounts(hd, sd, radio, unknown int)
	IncStreamURLBuild(status string)
	IncRefreshFailure(reason string)
	RecordXMLTV(enabled bool, channels int, err error)
	RecordPlaylistFileValidity(fileType string, valid bool)
	RecordEPGCollection(programmes, channels int, duration float64)
}

MetricsRecorder defines the interface for recording metrics

type OpenWebIFClient added in v1.7.0

type OpenWebIFClient interface {
	Bouquets(ctx context.Context) (map[string]string, error)
	Services(ctx context.Context, bouquetRef string) ([][]string, error)
	StreamURL(ctx context.Context, serviceRef, serviceName string) (string, error)
}

OpenWebIFClient defines the interface for interacting with OpenWebIF receivers

type Options added in v1.7.0

type Options struct {
	Force       bool // Force refresh even if recent data exists
	IncludeEPG  bool // Include EPG data collection
	DryRun      bool // Skip actual file writes
	Parallelism int  // Max parallel workers (0 = GOMAXPROCS)
}

Options controls the behavior of the refresh operation

func DefaultOptions added in v1.7.0

func DefaultOptions() Options

DefaultOptions returns sensible default options

func DefaultOptionsFromConfig added in v1.7.0

func DefaultOptionsFromConfig(cfg Config) Options

DefaultOptionsFromConfig creates options from config

type RefreshStats added in v1.7.0

type RefreshStats struct {
	StartTime       time.Time
	EndTime         time.Time
	DurationMS      int64
	ChannelsTotal   int
	BouquetsTotal   int
	EPGProgrammes   int
	HDChannels      int
	SDChannels      int
	RadioChannels   int
	UnknownChannels int
	Errors          []string
}

RefreshStats contains statistics about the refresh operation

type Status

type Status struct {
	Version       string    `json:"version"`
	LastRun       time.Time `json:"lastRun"`
	Channels      int       `json:"channels"`
	Bouquets      int       `json:"bouquets,omitempty"`      // Number of bouquets processed
	EPGProgrammes int       `json:"epgProgrammes,omitempty"` // Number of EPG programmes collected
	DurationMS    int64     `json:"durationMs,omitempty"`    // Duration of last refresh in milliseconds
	Error         string    `json:"error,omitempty"`
}

Status represents the current state of the refresh job

func Refresh

func Refresh(ctx context.Context, cfg Config) (*Status, error)

Refresh performs the complete refresh cycle: fetch bouquets → services → write M3U + XMLTV

Jump to

Keyboard shortcuts

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