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 ¶
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(commitSHA string) error, retryConfig RetryConfig, commitSHA string) *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) - commitSHA: Commit SHA to pass to callback for error context
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
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.