daemon

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatePriority

func CalculatePriority(info os.FileInfo) int

CalculatePriority calculates job priority based on file modification time More recently modified files get higher priority

func DetectServiceManager

func DetectServiceManager() string

DetectServiceManager returns the appropriate service manager for the platform

func GetAlreadyRunningHelp

func GetAlreadyRunningHelp() string

GetAlreadyRunningHelp returns platform-specific help for "already running" errors

func GetNotRunningHelp

func GetNotRunningHelp() string

GetNotRunningHelp returns platform-specific help for "not running" errors

func GetServiceManagerHint

func GetServiceManagerHint(sm string) string

GetServiceManagerHint returns helpful hint for managing daemon as service

func GetSignalErrorHelp

func GetSignalErrorHelp(pid int) string

GetSignalErrorHelp returns platform-specific help for signal errors

func IsServiceManaged

func IsServiceManaged() bool

IsServiceManaged attempts to detect if daemon is running under service manager

Types

type Daemon

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

Daemon manages background index computation

func New

func New(cfg *config.Config, logger *slog.Logger, logWriter *lumberjack.Logger) (*Daemon, error)

New creates a new daemon instance

func (*Daemon) GetConfig

func (d *Daemon) GetConfig() *config.Config

GetConfig returns the current configuration (thread-safe)

func (*Daemon) GetLogger

func (d *Daemon) GetLogger() *slog.Logger

GetLogger returns the current logger (thread-safe)

func (*Daemon) GetSemanticAnalyzer

func (d *Daemon) GetSemanticAnalyzer() *semantic.Analyzer

GetSemanticAnalyzer returns the current semantic analyzer (lock-free)

func (*Daemon) Rebuild

func (d *Daemon) Rebuild() error

Rebuild forces an immediate index rebuild

func (*Daemon) ReloadConfig

func (d *Daemon) ReloadConfig() error

ReloadConfig reloads configuration and applies changes

func (*Daemon) SetConfig

func (d *Daemon) SetConfig(cfg *config.Config)

SetConfig sets the configuration atomically (thread-safe)

func (*Daemon) SetLogger

func (d *Daemon) SetLogger(l *slog.Logger)

SetLogger sets the logger atomically (thread-safe)

func (*Daemon) SetSemanticAnalyzer

func (d *Daemon) SetSemanticAnalyzer(a *semantic.Analyzer)

SetSemanticAnalyzer sets the semantic analyzer atomically (lock-free)

func (*Daemon) Start

func (d *Daemon) Start() error

Start starts the daemon

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop stops the daemon

type HTTPServer added in v0.12.0

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

HTTPServer manages the daemon's unified HTTP API

func NewHTTPServer added in v0.12.0

func NewHTTPServer(hub *SSEHub, metrics *HealthMetrics, logger *slog.Logger) *HTTPServer

NewHTTPServer creates a new unified HTTP server

func (*HTTPServer) Start added in v0.12.0

func (s *HTTPServer) Start(port int) error

Start starts the HTTP server on the specified port If a server is already running, it will be stopped first (supports hot-reload)

func (*HTTPServer) Stop added in v0.12.0

func (s *HTTPServer) Stop() error

Stop gracefully shuts down the HTTP server

type HealthMetrics

type HealthMetrics struct {
	StartTime        time.Time `json:"start_time"`
	Uptime           string    `json:"uptime"`
	UptimeSeconds    int64     `json:"uptime_seconds"`
	FilesProcessed   int       `json:"files_processed"`
	APICalls         int       `json:"api_calls"`
	CacheHits        int       `json:"cache_hits"`
	Errors           int       `json:"errors"`
	LastBuildTime    time.Time `json:"last_build_time"`
	LastBuildSuccess bool      `json:"last_build_success"`
	IndexFileCount   int       `json:"index_file_count"`
	WatcherActive    bool      `json:"watcher_active"`
	// contains filtered or unexported fields
}

HealthMetrics tracks daemon health statistics

func NewHealthMetrics

func NewHealthMetrics() *HealthMetrics

NewHealthMetrics creates a new health metrics tracker

func (*HealthMetrics) DecrementIndexFileCount added in v0.12.1

func (h *HealthMetrics) DecrementIndexFileCount()

DecrementIndexFileCount decrements the index file count by 1

func (*HealthMetrics) GetSnapshot

func (h *HealthMetrics) GetSnapshot() HealthSnapshot

GetSnapshot returns a snapshot of current metrics

func (*HealthMetrics) IncrementIndexFileCount added in v0.12.1

func (h *HealthMetrics) IncrementIndexFileCount()

IncrementIndexFileCount increments the index file count by 1

func (*HealthMetrics) RecordAPICall added in v0.12.1

func (h *HealthMetrics) RecordAPICall()

RecordAPICall increments the API calls counter

func (*HealthMetrics) RecordBuild

func (h *HealthMetrics) RecordBuild(filesProcessed, apiCalls, cacheHits, errors int, success bool)

RecordBuild records a build attempt

func (*HealthMetrics) RecordCacheHit added in v0.12.1

func (h *HealthMetrics) RecordCacheHit()

RecordCacheHit increments the cache hits counter

func (*HealthMetrics) RecordError

func (h *HealthMetrics) RecordError()

RecordError increments the error counter

func (*HealthMetrics) RecordFileProcessed added in v0.12.1

func (h *HealthMetrics) RecordFileProcessed()

RecordFileProcessed increments the files processed counter

func (*HealthMetrics) SetIndexFileCount

func (h *HealthMetrics) SetIndexFileCount(count int)

SetIndexFileCount updates the current index file count

func (*HealthMetrics) SetWatcherActive

func (h *HealthMetrics) SetWatcherActive(active bool)

SetWatcherActive sets the watcher active status

type HealthSnapshot

type HealthSnapshot struct {
	StartTime        time.Time `json:"start_time"`
	Uptime           string    `json:"uptime"`
	UptimeSeconds    int64     `json:"uptime_seconds"`
	FilesProcessed   int       `json:"files_processed"`
	APICalls         int       `json:"api_calls"`
	CacheHits        int       `json:"cache_hits"`
	Errors           int       `json:"errors"`
	LastBuildTime    time.Time `json:"last_build_time"`
	LastBuildSuccess bool      `json:"last_build_success"`
	IndexFileCount   int       `json:"index_file_count"`
	WatcherActive    bool      `json:"watcher_active"`
}

HealthSnapshot represents a point-in-time snapshot of health metrics without the mutex, safe for copying and serialization

type Job

type Job struct {
	Path     string
	Info     os.FileInfo
	Priority int // Higher priority = process first
}

Job represents a file processing job

type JobResult

type JobResult struct {
	Entry types.IndexEntry
	Error error
}

JobResult represents the result of processing a job

type PoolStats

type PoolStats struct {
	JobsProcessed int
	JobsQueued    int
	CacheHits     int
	APICalls      int
	Errors        int
}

PoolStats tracks worker pool statistics

type SSEClient added in v0.12.0

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

SSEClient represents a connected SSE client

type SSEHub added in v0.12.0

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

SSEHub manages Server-Sent Events broadcasting for index updates

func NewSSEHub added in v0.12.0

func NewSSEHub(logger *slog.Logger) *SSEHub

NewSSEHub creates a new SSE broadcast hub

func (*SSEHub) BroadcastIndexUpdate added in v0.12.0

func (h *SSEHub) BroadcastIndexUpdate()

BroadcastIndexUpdate sends index update notification to all connected clients

func (*SSEHub) ClientCount added in v0.12.0

func (h *SSEHub) ClientCount() int

ClientCount returns the number of connected SSE clients

type WorkerPool

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

WorkerPool manages parallel file processing with rate limiting

func NewWorkerPool

func NewWorkerPool(
	workers int,
	rateLimitPerMin int,
	metadataExtractor *metadata.Extractor,
	semanticAnalyzer *semantic.Analyzer,
	cacheManager *cache.Manager,
	logger *slog.Logger,
	ctx context.Context,
) *WorkerPool

NewWorkerPool creates a new worker pool

func (*WorkerPool) GetStats

func (wp *WorkerPool) GetStats() PoolStats

GetStats returns current pool statistics

func (*WorkerPool) Results

func (wp *WorkerPool) Results() <-chan JobResult

Results returns the result channel

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

Start starts the worker pool

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop stops the worker pool gracefully

func (*WorkerPool) Submit

func (wp *WorkerPool) Submit(job Job)

Submit submits a job to the pool

func (*WorkerPool) SubmitBatch

func (wp *WorkerPool) SubmitBatch(jobs []Job)

SubmitBatch submits multiple jobs, sorted by priority

Jump to

Keyboard shortcuts

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