progress

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package progress provides the shared progress-logging and resumable checkpoint helpers used by every cryptolab tool: throttled structured logging for high-volume search loops, an append-only JSONL survivor log, and an atomically-written JSON checkpoint so multi-hour runs survive a kill and resume where they left off.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCheckpoint

func LoadCheckpoint(path string, v any) (found bool, err error)

LoadCheckpoint reads a checkpoint into v. A missing file is not an error (found is false), so callers can treat "no checkpoint" as "start fresh".

func SaveCheckpoint

func SaveCheckpoint(path string, v any) error

SaveCheckpoint atomically writes v as pretty JSON to path (temp file in the same directory + rename), so a killed process never leaves a half-written checkpoint.

Types

type JSONL

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

JSONL is an append-only newline-delimited JSON writer for survivor logs.

func OpenJSONL

func OpenJSONL(dir, name string) (*JSONL, error)

OpenJSONL creates/truncates a .jsonl file at dir/name. A nil JSONL (when dir is empty) is safe to Append to and Close — it no-ops.

func (*JSONL) Append

func (j *JSONL) Append(v any) error

Append writes one JSON record. Safe on a nil receiver.

func (*JSONL) Close

func (j *JSONL) Close() error

Close flushes and closes the file. Safe on a nil receiver.

type Throttle

type Throttle struct {
	Logger   *slog.Logger
	Msg      string
	Every    int           // emit at most once per this many ticks (0 = no count gate)
	Interval time.Duration // emit at most once per this duration (0 = no time gate)
	// contains filtered or unexported fields
}

Throttle rate-limits high-volume progress lines. A search loop that visits millions of candidates calls Tick every iteration but only emits a log line every Every iterations or every Interval, whichever comes first — plus an unconditional line whenever the caller reports a new best.

func (*Throttle) Best

func (t *Throttle) Best(args ...any)

Best forces an immediate line (a new best candidate is always worth logging regardless of throttle state).

func (*Throttle) Tick

func (t *Throttle) Tick(args ...any)

Tick advances the counter and emits a throttled line carrying args.

Jump to

Keyboard shortcuts

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