tieredwatcher

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tieredwatcher implements tiered file watching with a HOT tier using real-time fsnotify and a COLD tier using periodic polling, reducing file descriptor usage while keeping recently active sessions responsive.

Index

Constants

View Source
const (
	// ColdPollInterval is how often COLD tier sessions are polled for changes.
	ColdPollInterval = 30 * time.Second
	// HotInactivityTimeout demotes sessions to COLD after this period without activity.
	HotInactivityTimeout = 5 * time.Minute
	// FrozenThreshold is the duration after which unchanged COLD sessions stop being polled.
	FrozenThreshold = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// RootDir is the root directory to watch
	RootDir string
	// FilePattern is the file extension to watch (e.g., ".jsonl")
	FilePattern string
	// ExtractID extracts session ID from a file path
	ExtractID func(path string) string
	// ScanDir scans a directory and returns session info (optional, for COLD tier)
	ScanDir func(dir string) ([]SessionInfo, error)
	// Filter optionally filters watched paths (overrides FilePattern if set)
	Filter func(path string) bool
}

Config holds configuration for creating a TieredWatcher.

type Manager

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

Manager coordinates tiered watching across multiple adapters. It merges events from all adapter watchers into a single channel.

func NewManager

func NewManager() *Manager

NewManager creates a new tiered watcher manager.

func (*Manager) AddWatcher

func (m *Manager) AddWatcher(adapterID string, tw *TieredWatcher, ch <-chan adapter.Event)

AddWatcher adds a tiered watcher for an adapter and starts forwarding its events.

func (*Manager) Close

func (m *Manager) Close() error

Close shuts down all watchers.

func (*Manager) Closers

func (m *Manager) Closers() []io.Closer

Closers returns all io.Closers for the manager's watchers.

func (*Manager) Events

func (m *Manager) Events() <-chan adapter.Event

Events returns the merged event channel.

func (*Manager) PromoteSession

func (m *Manager) PromoteSession(adapterID, sessionID string)

PromoteSession promotes a session to HOT tier for a specific adapter. If adapterID is empty, promotes across all watchers.

func (*Manager) RegisterSession

func (m *Manager) RegisterSession(adapterID, sessionID, path string)

RegisterSession registers a session with the appropriate watcher.

func (*Manager) SetHotTarget

func (m *Manager) SetHotTarget(adapterID string, target int)

SetHotTarget sets the desired HOT session count for a specific adapter.

func (*Manager) Stats

func (m *Manager) Stats() (hotCount, coldCount, frozenCount, watchedDirs int)

Stats returns aggregate statistics across all watchers.

func (*Manager) Touch

func (m *Manager) Touch(adapterID, sessionID string)

Touch unfreezes a session for a specific adapter so it will be polled again. If adapterID is empty, touches across all watchers.

type SessionInfo

type SessionInfo struct {
	ID       string    // Session ID (e.g., filename without extension)
	Path     string    // Full path to session file
	ModTime  time.Time // Last known modification time
	LastHot  time.Time // When this session was last in HOT tier or accessed
	FileSize int64     // Last known file size
	Frozen   bool      // true = unchanged >24h, skip in pollColdSessions
}

SessionInfo tracks a watched session's path and modification time.

type TieredCloser

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

TieredCloser wraps TieredWatcher to implement io.Closer.

func (*TieredCloser) Close

func (tc *TieredCloser) Close() error

Close implements io.Closer.

type TieredWatcher

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

TieredWatcher manages tiered watching for a single adapter's sessions.

func New

func New(cfg Config) (*TieredWatcher, <-chan adapter.Event, error)

New creates a new TieredWatcher.

func (*TieredWatcher) Close

func (tw *TieredWatcher) Close() error

Close shuts down the watcher.

func (*TieredWatcher) NewCloser

func (tw *TieredWatcher) NewCloser() io.Closer

NewCloser returns an io.Closer for the TieredWatcher.

func (*TieredWatcher) PromoteToHot

func (tw *TieredWatcher) PromoteToHot(sessionID string)

PromoteToHot promotes a session to the HOT tier (e.g., when user selects it).

func (*TieredWatcher) RegisterSession

func (tw *TieredWatcher) RegisterSession(id, path string)

RegisterSession adds a session to tracking (starts in COLD tier).

func (*TieredWatcher) RegisterSessions

func (tw *TieredWatcher) RegisterSessions(sessions []SessionInfo)

RegisterSessions adds multiple sessions to tracking.

func (*TieredWatcher) SetHotTarget

func (tw *TieredWatcher) SetHotTarget(target int)

SetHotTarget sets the desired number of HOT sessions and rebuilds the HOT set.

func (*TieredWatcher) Stats

func (tw *TieredWatcher) Stats() (hotCount, coldCount, frozenCount, watchedDirs int)

Stats returns current watcher statistics.

func (*TieredWatcher) Touch

func (tw *TieredWatcher) Touch(sessionID string)

Touch unfreezes a session so it will be polled again in COLD tier.

Jump to

Keyboard shortcuts

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