sessionwatch

package
v0.23.5 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sessionwatch polls a session's DB state and source-file mtime, emitting a tick each time the session version changes. Shared by the HTTP SSE handler and the CLI `session watch` command.

Index

Constants

View Source
const (
	// PollInterval is how often the session monitor checks
	// the database for changes.
	PollInterval = 1500 * time.Millisecond
	// HeartbeatTicks is how often a keepalive is sent to
	// the client. Expressed as a multiple of PollInterval
	// (~30s).
	HeartbeatTicks = 20
	// SyncFallbackDelay is how long to wait after detecting
	// a file mtime change before attempting a direct sync.
	// This gives the file watcher time to process the change
	// through the normal SyncPaths pipeline.
	SyncFallbackDelay = 5 * time.Second
)

Variables

This section is empty.

Functions

func StatMtime

func StatMtime(path string) int64

StatMtime returns the file's modification time in nanoseconds, or 0 if the file cannot be stat'd.

Types

type Watcher

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

Watcher emits a tick on Events() each time the session's DB state changes, with an optional file-mtime-triggered direct sync when the engine is non-nil.

func New

func New(d db.Store, engine *sync.Engine) *Watcher

New returns a Watcher backed by the given store. engine may be nil to disable file-mtime fallback sync (PG-read mode).

func (*Watcher) Events

func (w *Watcher) Events(
	ctx context.Context, sessionID string,
) <-chan struct{}

Events polls the database for session changes and signals the returned channel when the message count changes. This is decoupled from file I/O — the file watcher handles syncing files to the database, and this monitor detects the resulting DB changes.

As a fallback when file watching or incremental sync misses a DB update, it also monitors the source file's mtime and triggers a direct sync when the DB hasn't been updated within SyncFallbackDelay.

Jump to

Keyboard shortcuts

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