toolout

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package toolout keeps the tool-out directory, where truncated answers are saved, from growing without bound: age limit, size cap, and a periodic sweep.

Index

Constants

View Source
const (
	// DefaultTTL is how long a saved answer stays readable.
	DefaultTTL = 24 * time.Hour
	// DefaultMax is the size cap of one tool-out directory.
	DefaultMax = int64(256 << 20)
	// Interval is how often a running process sweeps. Измеренный поток — около
	// 2 МиБ в час на один болтливый сервер, поэтому час давал перелёт потолка в
	// разы между чистками.
	Interval = 10 * time.Minute
)
View Source
const AnonymousOwner = "anonymous"

AnonymousOwner marks a dump whose caller presented no key: an open set, or stdio. Such a dump is readable by a caller that has no key either.

Variables

This section is empty.

Functions

func Base

func Base() string

Base is the data directory this process writes its tool-out into.

func Dir

func Dir(base string) string

Dir is where an oversized answer is written; created on first use.

func OwnerPath added in v0.6.0

func OwnerPath(dump string) string

OwnerPath is the sidecar that keeps a dump to the key that asked for it: one line, the key fingerprint the counters use.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize accepts plain bytes and the K/KiB/M/MiB/G/GiB suffixes.

func Run

func Run(ctx context.Context, base string, cfg Config, interval time.Duration, log *slog.Logger) <-chan struct{}

Run sweeps now and then every interval until ctx is done. The returned channel closes when the goroutine exits, so a test can wait for it.

func Usage

func Usage(base string) (size int64, count int, oldest time.Time, err error)

Usage sums the tool-out files under base and reports the oldest one — the next to expire. fs.ErrNotExist means there is no tool-out at all.

Types

type Config

type Config struct {
	TTL time.Duration
	Max int64
}

Config is the retention policy for tool-out.

func FromEnv

func FromEnv() (Config, []string)

FromEnv reads MCPRIG_TOOLOUT_TTL and MCPRIG_TOOLOUT_MAX. A value that does not parse is reported back as a warning and the default is used.

type Report

type Report struct {
	Removed int
	Freed   int64
}

Report is what one sweep did.

func Sweep

func Sweep(base string, cfg Config, now time.Time) (Report, error)

Sweep applies the policy to base/tool-out and every set's tool-out under base: the panel shares one data directory with its set proxies.

Jump to

Keyboard shortcuts

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