watcher

package
v0.0.0-...-e9a10d7 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package watcher provides file system watching with debouncing and retry logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolvePath

func ResolvePath(path string) (string, error)

ResolvePath resolves a path to an absolute path.

Types

type FileWatcher

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

FileWatcher watches a file for changes and triggers callbacks with debouncing and retry logic.

func NewFileWatcher

func NewFileWatcher(path string, pollInterval time.Duration, debounce time.Duration, callback func() error, retryConfig RetryConfig) *FileWatcher

NewFileWatcher creates a new file watcher.

Parameters: - path: Absolute path to the file to watch - pollInterval: How often to check for changes (e.g., 5s) - debounce: How long to wait after last change before triggering (e.g., 5s) - callback: Function to call when a change is detected (should be idempotent) - retryConfig: Retry configuration for callback failures (use DefaultRetryConfig() for defaults)

func (*FileWatcher) Run

func (fw *FileWatcher) Run(initialRun bool) error

Run starts the watch loop. Blocks until stopped.

The loop: 1. Checks file modification time on each poll interval 2. If changed, waits for debounce period 3. Re-checks to avoid duplicate triggers 4. Calls callback with retry logic if still changed 5. Handles callback errors by logging but continuing to watch

func (*FileWatcher) Stop

func (fw *FileWatcher) Stop()

Stop stops the watch loop.

type RetryConfig

type RetryConfig struct {
	MaxRetries        int           // Maximum number of retry attempts (0 = no retry)
	InitialBackoff    time.Duration // Initial backoff duration (e.g., 1s)
	MaxBackoff        time.Duration // Maximum backoff duration (e.g., 60s)
	BackoffMultiplier float64       // Multiplier for exponential backoff (e.g., 2.0)
}

RetryConfig configures retry behavior for callback failures.

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns a sensible default retry configuration.

Jump to

Keyboard shortcuts

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