queue

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package queue manages the learn inbox: job files written by the SessionEnd hook, a lockfile so only one worker mines at a time, and per-transcript byte cursors. Deletion is parse-gated (ecosystem lesson): a job is removed only after a successfully processed mine — crashes and retries never lose observations. Three failures move the job to inbox/failed/ (circuit break).

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("queue: another learn worker is running")

ErrLocked reports another live worker holds the lock — the caller should simply exit; the queue drains on the next run.

Functions

func Done

func Done(j Job) error

Done removes a successfully processed job (parse-gated: call only after the mine result was parsed and persisted).

func Fail

func Fail(j Job) (parked bool, err error)

Fail records one failed attempt. The job file survives under a .fN suffix until maxAttempts, then moves to inbox/failed/ for manual inspection. Returns true when the job was parked (no more retries).

func ShouldMine

func ShouldMine(cur Cursor, size int64, sessionEnd bool, now time.Time) bool

ShouldMine decides whether a transcript has enough new content to be worth parsing. size is the transcript's current byte size.

Types

type Cursor

type Cursor struct {
	Offset  int64     `json:"offset"`
	MinedAt time.Time `json:"mined_at"`
}

Cursor is one transcript's mining progress: everything before Offset has been mined once (plan §learning A — each region mined exactly once).

type Cursors

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

Cursors is the persistent transcript_path → Cursor map.

func LoadCursors

func LoadCursors(stateDir string) *Cursors

LoadCursors reads state/learn_cursors.json; a missing or corrupt file yields an empty map (worst case: some regions are mined twice — the dedup stage absorbs that).

func (*Cursors) Get

func (c *Cursors) Get(transcriptPath string) Cursor

Get returns the cursor for a transcript (zero value = never mined).

func (*Cursors) Save

func (c *Cursors) Save() error

Save writes the map atomically (temp + rename) and prunes entries whose transcript no longer exists, so the file cannot grow without bound.

func (*Cursors) Set

func (c *Cursors) Set(transcriptPath string, cur Cursor)

Set records progress for a transcript.

type Job

type Job struct {
	SessionID      string `json:"session_id"`
	TranscriptPath string `json:"transcript_path"`
	CWD            string `json:"cwd"`
	EnqueuedAt     string `json:"enqueued_at"`
	// contains filtered or unexported fields
}

Job is one queued transcript, as enqueued by the SessionEnd hook.

func List

func List(inboxDir string) ([]Job, error)

List reads every pending job (including previously failed retries), oldest first. A malformed job file is skipped, never fatal.

func (Job) Attempts

func (j Job) Attempts() int

func (Job) Path

func (j Job) Path() string

Path returns the job file location; Attempts the prior failure count.

type Lock

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

Lock is a held lockfile.

func TryLock

func TryLock(stateDir string) (*Lock, error)

TryLock acquires state/learn.lock exclusively. A stale lockfile (older than staleLock) is broken once and re-acquired.

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock releases the lockfile.

Jump to

Keyboard shortcuts

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