journal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package journal defines the append-only fact log that records everything that ever happened to tasks. All derived views (queue, DLQ, stats) are projections over these facts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fact

type Fact struct {
	Seq     int64           `json:"seq"`
	Time    time.Time       `json:"time"`
	TaskID  string          `json:"taskId"`
	Type    FactType        `json:"type"`
	Owner   string          `json:"owner,omitempty"`
	Attempt int             `json:"attempt,omitempty"`
	Error   string          `json:"error,omitempty"`
	Detail  json.RawMessage `json:"detail,omitempty"`
}

Fact is one immutable observation about one task.

type FactType

type FactType string

FactType enumerates the kinds of facts that can be recorded.

const (
	Enqueued     FactType = "task.enqueued"
	Claimed      FactType = "task.claimed"
	Heartbeat    FactType = "task.heartbeat"
	Completed    FactType = "task.completed"
	Failed       FactType = "task.failed"        // attempt failed, will retry
	DeadLettered FactType = "task.dead-lettered" // attempts exhausted
	Cancelled    FactType = "task.cancelled"
	// CancelRequested records an operator's request to stop a Running
	// task. The fact IS the flag: the executing worker observes it at its
	// next heartbeat, cancels the execution context, and records
	// task.cancelled; a crashed worker's expired lease finalizes the same
	// cancel at reclaim. No task-row column mirrors it.
	CancelRequested FactType = "task.cancel-requested"
	Released        FactType = "task.released" // lease expired, back to pending
	Requeued        FactType = "task.requeued" // preflight refusal, no attempt burned
	// Orphaned records that a Running task's lease expired and NO worker
	// reclaimed it (the worker died with the pool down). It is an
	// observation, not a state change: the task stays Running until a
	// ClaimDue reclaim (or a human) picks it up. Appended idempotently by
	// Store.MarkOrphaned, so `tq show` can explain a stranded task.
	Orphaned FactType = "task.orphaned"
)

type Journal

type Journal interface {
	// Append records a fact. Implementations must assign Seq and Time when zero.
	Append(ctx context.Context, f Fact) (Fact, error)
	// All returns every fact in Seq order.
	All(ctx context.Context) ([]Fact, error)
	// Since returns facts with Seq strictly greater than after, in Seq order.
	Since(ctx context.Context, after int64) ([]Fact, error)
}

Journal is the persistence boundary for facts.

type MemoryJournal

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

MemoryJournal is an in-memory Journal for tests and ephemeral queues.

func NewMemoryJournal

func NewMemoryJournal() *MemoryJournal

NewMemoryJournal returns an empty in-memory journal.

func (*MemoryJournal) All

func (m *MemoryJournal) All(_ context.Context) ([]Fact, error)

All returns every fact in Seq order.

func (*MemoryJournal) Append

func (m *MemoryJournal) Append(_ context.Context, f Fact) (Fact, error)

Append records the fact, assigning Seq and Time when zero.

func (*MemoryJournal) Since

func (m *MemoryJournal) Since(_ context.Context, after int64) ([]Fact, error)

Since returns facts with Seq strictly greater than after.

Directories

Path Synopsis
cqrs module

Jump to

Keyboard shortcuts

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