watcher

package
v0.0.0-...-3cb017b Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package watcher provides interfaces and implementations for monitoring resources and triggering actions on changes. It supports file system watching and can be extended to monitor other resource types like metrics, endpoints, or configuration sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileWatcher

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

FileWatcher monitors a file for changes using fsnotify.

func NewFileWatcher

func NewFileWatcher(filePath string, opts ...FileWatcherOption) *FileWatcher

NewFileWatcher creates a new file watcher for the specified file path. Accepts optional configuration via FileWatcherOption functions.

func (*FileWatcher) Watch

func (fw *FileWatcher) Watch(ctx context.Context, onChange func()) error

Watch starts monitoring the file and calls onChange when the file is modified. It blocks until the context is cancelled and returns nil on clean shutdown.

type FileWatcherOption

type FileWatcherOption func(*FileWatcher)

FileWatcherOption configures a FileWatcher.

func WithDebounceDelay

func WithDebounceDelay(delay time.Duration) FileWatcherOption

WithDebounceDelay sets the debounce delay for file change events. Default is 200ms.

func WithEventMask

func WithEventMask(mask fsnotify.Op) FileWatcherOption

WithEventMask sets which filesystem events to watch for. Default is Create|Write|Remove|Rename.

type GPUBindUnbindWatcher

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

GPUBindUnbindWatcher monitors GPU bind/unbind events using DCGM_FI_BIND_UNBIND_EVENT field This is a GLOBAL field (DCGM_FS_GLOBAL) that tracks system-wide driver attach/detach events Requires DCGM 4.5.0 or later

func NewGPUBindUnbindWatcher

func NewGPUBindUnbindWatcher(opts ...GPUBindUnbindWatcherOption) *GPUBindUnbindWatcher

NewGPUBindUnbindWatcher creates a new GPU bind/unbind event watcher

func (*GPUBindUnbindWatcher) Watch

func (w *GPUBindUnbindWatcher) Watch(ctx context.Context, onChange func()) error

Watch starts monitoring GPU bind/unbind events and calls onChange when detected It blocks until the context is cancelled onChange is called for any GPU topology change (bind or unbind)

type GPUBindUnbindWatcherOption

type GPUBindUnbindWatcherOption func(*GPUBindUnbindWatcher)

GPUBindUnbindWatcherOption configures a GPUBindUnbindWatcher

func WithPollInterval

func WithPollInterval(interval time.Duration) GPUBindUnbindWatcherOption

WithPollInterval sets how often to check for bind/unbind events DCGM recommends 1 second for this field (see dcgm_fields.h) Default is 1 second

type Watcher

type Watcher interface {
	// Watch starts monitoring the resource and blocks until ctx is cancelled.
	// Calls onChange() when the resource changes.
	// Returns nil on clean shutdown, or an error if monitoring fails.
	Watch(ctx context.Context, onChange func()) error
}

Watcher monitors a resource and triggers callback on changes. Implementations must be context-aware and exit gracefully when context is cancelled.

Jump to

Keyboard shortcuts

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