session

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package session manages per-invocation lifecycle: a unique session ID, the profile file path, and ordered cleanup hooks.

Index

Constants

View Source
const StaleProfileMaxAge = 1 * time.Hour

StaleProfileMaxAge bounds how old a leftover profile file can be before the next session.New() considers it abandoned and removes it. Profiles orphaned by SIGKILL of the parent ora process are cleaned up on the next invocation rather than waiting for `doctor --sweep`.

Variables

This section is empty.

Functions

func ListStaleProfiles

func ListStaleProfiles(dir string, maxAge time.Duration) []string

ListStaleProfiles returns absolute paths of leftover ora profile files in dir that are older than maxAge. Used by both `ora doctor` (to display) and the per-session sweep (to remove); having one predicate keeps the two consumers from drifting.

func NewID

func NewID() string

NewID returns a fresh ULID string (26 characters, sortable, no central coordination required). IDs generated in tight loops within the same millisecond are guaranteed to be monotonically increasing — the JSON event stream relies on this for ordering semantics.

Types

type Session

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

Session bundles a unique ID, the on-disk profile path, and ordered cleanup hooks. Cleanup is idempotent and runs all hooks in LIFO order.

func New

func New() *Session

New initializes a session: assigns an ID and computes the profile path under ${TMPDIR}. As a side effect, sweeps any leftover ora profile files older than StaleProfileMaxAge to defend against SIGKILL leaks.

func (*Session) Cleanup

func (s *Session) Cleanup() error

Cleanup runs all registered hooks in LIFO order, then deletes the profile file. Safe to call concurrently — only the first invocation across all goroutines runs the hooks; subsequent calls return the same aggregated error.

func (*Session) ID

func (s *Session) ID() string

ID returns the session ULID.

func (*Session) OnCleanup

func (s *Session) OnCleanup(fn func() error)

OnCleanup registers a hook to run during Cleanup. Hooks run in LIFO order so resources started last are torn down first. Safe for concurrent use; calling OnCleanup AFTER Cleanup has started logs a warning and drops the hook (a programming error: lifecycle hooks should always be registered before triggering cleanup).

func (*Session) ProfilePath

func (s *Session) ProfilePath() string

ProfilePath returns the absolute path the profile will be written to.

func (*Session) WriteProfile

func (s *Session) WriteProfile(content string) error

WriteProfile writes the Seatbelt profile content to ProfilePath with mode 0600 (only the user can read).

Jump to

Keyboard shortcuts

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