worker

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintErrors

func PrintErrors(errors []ProcessingError)

PrintErrors logs errors in a structured way.

func WorkerPool

func WorkerPool(ctx context.Context, m *WorkerPoolManager, trackExecution bool) error

WorkerPool processes files concurrently and updates metrics.

Types

type Job

type Job struct {
	InputPath  string
	OutputPath string
}

Job represents a file processing task.

type JobExecutionTime

type JobExecutionTime struct {
	FilePath string
	Duration time.Duration
}

JobExecutionTime stores execution duration per file.

type Metrics

type Metrics struct {
	FilesProcessed       int       `json:"files_processed"`
	DirectoriesProcessed int       `json:"directories_processed"`
	ErrorsEncountered    int       `json:"errors_encountered"`
	SkippedFiles         int       `json:"skipped_files"`
	StartTime            time.Time `json:"start_time"`
	ElapsedTime          string    `json:"elapsed_time"`
	// contains filtered or unexported fields
}

Metrics tracks processing statistics.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics initializes the metrics struct.

func (*Metrics) IncrementDirectory

func (m *Metrics) IncrementDirectory()

IncrementDirectory updates the directory counter.

func (*Metrics) IncrementError

func (m *Metrics) IncrementError()

IncrementError updates the error counter.

func (*Metrics) IncrementFile

func (m *Metrics) IncrementFile()

IncrementFile updates the file counter.

func (*Metrics) IncrementSkippedFile

func (m *Metrics) IncrementSkippedFile()

IncrementSkippedFile updates the skipped file counter.

func (*Metrics) PrintSummary

func (m *Metrics) PrintSummary(errors []ProcessingError, skippedFiles []ProcessingError, verbose bool)

PrintSummary prints the summary in text format.

func (*Metrics) Reset

func (m *Metrics) Reset()

Reset clears all metrics and resets the start time.

func (*Metrics) SummaryAsString

func (m *Metrics) SummaryAsString(errors []ProcessingError, skippedFiles []ProcessingError, summaryOpts *SummaryOptions) (string, error)

SummaryAsString generates and returns the processing summary in the requested format.

func (*Metrics) ToJSONFile

func (m *Metrics) ToJSONFile(errors []ProcessingError, skippedFiles []ProcessingError, outputPath string) error

ToJSONFile writes the summary to a JSON file.

type ProcessingError

type ProcessingError struct {
	Source   string   `json:"source"`         // Source file path
	Dest     string   `json:"dest,omitempty"` // Expected output file path (if applicable)
	Message  string   `json:"message,omitempty"`
	Reason   string   `json:"reason,omitempty"`    // Why it was skipped
	SkipType SkipType `json:"skip_type,omitempty"` // Type of skip reason
}

ProcessingError stores detailed error info.

func CollectErrors

func CollectErrors(errorsChan <-chan ProcessingError) []ProcessingError

CollectErrors collects and aggregates errors or skipped files.

func FormatError

func FormatError(filePath string, err error) ProcessingError

FormatError formats errors for logging.

func FormatSkipReason

func FormatSkipReason(skipped SkippedFile) ProcessingError

FormatSkipReason creates a structured skip log entry.

type SkipType

type SkipType string

SkipType defines the type of skipped reason.

const (
	SkipUnsupportedFile  SkipType = "unsupported_file"  // Not CSS/JS
	SkipMismatchedPath   SkipType = "mismatched_output" // Structure mismatch
	SkipMissingTemplFile SkipType = "missing_templ"     // Missing templ file matches
	SkipUnchangedFile    SkipType = "unchanged_file"    // File not changed
	SkipQueueFull        SkipType = "queue_full"        // job queue is full
	SkipExcluded         SkipType = "user_skipped"      // Excluded by user
)

type SkippedFile

type SkippedFile struct {
	Source    string   // Path to the source file
	Dest      string   // Expected output file path (if applicable)
	InputDir  string   // Root input directory
	OutputDir string   // Root output directory
	Reason    string   // Why the file was skipped
	SkipType  SkipType // Type of skip reason
}

SkippedFile holds metadata about a skipped file.

type SummaryFormat

type SummaryFormat string

SummaryFormat defines available summary output formats.

const (
	FormatNone    SummaryFormat = "none"
	FormatLong    SummaryFormat = "long"
	FormatCompact SummaryFormat = "compact"
	FormatJSON    SummaryFormat = "json"
)

type SummaryOptions

type SummaryOptions struct {
	Format     SummaryFormat // Output format: text, json, none
	ReportFile string        // File path to export JSON summary
	IsVerbose  bool
}

SummaryOptions holds configuration for summary output.

type WorkerPoolManager

type WorkerPoolManager struct {
	JobChan        chan Job
	ErrorsChan     chan ProcessingError
	SkippedChan    chan ProcessingError
	Metrics        *Metrics
	Factory        processor.ProcessorFactoryInterface
	InputDir       string
	OutputDir      string
	MarkerName     string
	ExecutionTimes []JobExecutionTime
	// contains filtered or unexported fields
}

WorkerPoolManager manages worker lifecycle.

func NewWorkerPoolManager

func NewWorkerPoolManager(opts WorkerPoolOptions) *WorkerPoolManager

NewWorkerPoolManager initializes a worker pool manager.

func (*WorkerPoolManager) StartWorkers

func (m *WorkerPoolManager) StartWorkers(ctx context.Context, numWorkers int, trackExecution bool) error

StartWorkers launches worker goroutines using `errgroup`.

type WorkerPoolOptions

type WorkerPoolOptions struct {
	Context              context.Context
	InputDir             string
	OutputDir            string
	ExcludeDir           string
	MarkerName           string
	NumWorkers           int
	IsProduction         bool // If `--prod` is set, process everything
	IsForce              bool // If `--force` is set, process everything
	IsTrackExecutionTime bool
}

WorkerPoolOptions holds configuration for the worker pool.

Jump to

Keyboard shortcuts

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