Documentation
¶
Index ¶
- type ArchiveStats
- type Store
- func (s *Store) ArchiveFactsBefore(ctx context.Context, cutoff int64) (int64, error)
- func (s *Store) ArchiveSummary(ctx context.Context) (ArchiveStats, error)
- func (s *Store) Cancel(ctx context.Context, id task.ID, reason string) error
- func (s *Store) CancelOwned(ctx context.Context, id task.ID, owner string) error
- func (s *Store) CancelRequested(ctx context.Context, id task.ID) (bool, error)
- func (s *Store) CancelRunning(ctx context.Context, id task.ID, reason string) error
- func (s *Store) ClaimDue(ctx context.Context, owner string, lease time.Duration) (task.Task, error)
- func (s *Store) Close() error
- func (s *Store) Complete(ctx context.Context, id task.ID, owner string, result json.RawMessage) error
- func (s *Store) CountFacts(ctx context.Context, ftype journal.FactType, since time.Time) (int64, error)
- func (s *Store) CountTasks(ctx context.Context, f queue.Filter) (int, error)
- func (s *Store) Enqueue(ctx context.Context, n task.New) (task.Task, error)
- func (s *Store) Facts(ctx context.Context, after int64, limit int) ([]journal.Fact, error)
- func (s *Store) FactsForTask(ctx context.Context, id string, limit int) ([]journal.Fact, error)
- func (s *Store) Fail(ctx context.Context, id task.ID, owner string, errText string, ...) error
- func (s *Store) FailPermanent(ctx context.Context, id task.ID, owner string, errText string, ...) error
- func (s *Store) Get(ctx context.Context, id task.ID) (task.Task, error)
- func (s *Store) HeadSeq(ctx context.Context) (int64, error)
- func (s *Store) Heartbeat(ctx context.Context, id task.ID, owner string, extend time.Duration) error
- func (s *Store) LastFacts(ctx context.Context, limit int) ([]journal.Fact, error)
- func (s *Store) List(ctx context.Context, f queue.Filter) ([]task.Task, error)
- func (s *Store) ListWatermarks(ctx context.Context) ([]queue.WatermarkEntry, error)
- func (s *Store) MarkOrphaned(ctx context.Context, cutoff time.Time) (int, error)
- func (s *Store) ProjectCounts(ctx context.Context) (map[string]map[task.Status]int, error)
- func (s *Store) Requeue(ctx context.Context, id task.ID, owner string, errText string, ...) error
- func (s *Store) RescueDead(ctx context.Context, id task.ID, maxAttempts int) error
- func (s *Store) SaveWatermark(ctx context.Context, consumer string, seq int64) error
- func (s *Store) SetWatermark(ctx context.Context, consumer string, seq int64) error
- func (s *Store) StatusCounts(ctx context.Context) (map[task.Status]int, error)
- func (s *Store) Watermark(ctx context.Context, consumer string) (int64, bool, error)
- type StoreOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArchiveStats ¶
type ArchiveStats struct {
Hot int64 // facts in the hot table
Archived int64 // facts in facts_archive
Watermark int64 // highest seq ever archived (-1 = never)
}
ArchiveStats reports hot vs archived fact counts and the compaction watermark (highest archived seq; -1 when nothing was archived yet).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the embedded, durable Store. One queue per database file.
Concurrency model: a single serialized write connection (MaxOpenConns(1)) plus WAL journal mode. All task mutations and their journal facts happen in one transaction, so the journal can never disagree with the task table. Multiple processes may open the same file; busy_timeout + WAL serialize cross-process writers.
func Open ¶
func Open(path string, opts ...StoreOption) (*Store, error)
Open opens (creating if needed) the queue database at path.
func (*Store) ArchiveFactsBefore ¶
ArchiveFactsBefore moves the facts of TERMINAL tasks (completed, dead, cancelled) whose highest fact seq is below cutoff into facts_archive — the hot-cold compaction prototype (ADR-0006). One transaction, one statement pair per task set; projections (tasks table) are untouched. Returns how many facts moved. NOT on the Store interface: an admin operation, not a queue operation.
func (*Store) ArchiveSummary ¶
func (s *Store) ArchiveSummary(ctx context.Context) (ArchiveStats, error)
ArchiveSummary reports hot/archived fact counts and the compaction watermark (highest archived seq; -1 when nothing was archived yet).
func (*Store) Cancel ¶
Cancel withdraws a Pending task. A non-empty reason is stored in the task.cancelled fact detail ("reason" key).
func (*Store) CancelOwned ¶
CancelOwned finalizes a cooperative cancel: Running -> Cancelled, written by the lease-holding worker after it stopped the execution. The operator's reason (from the cancel-requested fact) is carried onto the cancelled fact.
func (*Store) CancelRequested ¶
CancelRequested reports whether a cooperative cancel request is pending.
func (*Store) CancelRunning ¶
CancelRunning records a cooperative cancel request for a Running task. The task.cancel-requested fact IS the flag — no task-row column mirrors it (facts-first). A non-empty reason rides the request fact's detail and is carried onto the final task.cancelled fact by CancelOwned / the reclaim finalize. Idempotent: a second request appends nothing.
func (*Store) Complete ¶
func (s *Store) Complete(ctx context.Context, id task.ID, owner string, result json.RawMessage) error
Complete marks a Running task Completed.
func (*Store) CountFacts ¶
func (s *Store) CountFacts(ctx context.Context, ftype journal.FactType, since time.Time) (int64, error)
CountFacts counts facts of one type recorded at or after since.
func (*Store) CountTasks ¶
CountTasks counts the tasks matching the filter (COUNT(*) pushdown).
func (*Store) Enqueue ¶
Enqueue persists a new task and records task.enqueued. When New.DedupKey is set and a task with that key already exists, the stored task is returned unchanged — no duplicate row, no duplicate fact (idempotent enqueue).
func (*Store) Facts ¶
Facts returns journal facts with Seq > after, ascending, bounded to the most recent limit when > 0. The seq primary key makes the cursor scan O(limit) regardless of journal size.
func (*Store) FactsForTask ¶
FactsForTask returns one task's facts in Seq order, bounded to the most recent limit when > 0. Served by idx_facts_task (task_id, seq).
func (*Store) Fail ¶
func (s *Store) Fail( ctx context.Context, id task.ID, owner string, errText string, backoff time.Duration, evidence json.RawMessage, ) error
Fail records a failed attempt: retry with backoff or dead-letter.
func (*Store) FailPermanent ¶
func (s *Store) FailPermanent( ctx context.Context, id task.ID, owner string, errText string, evidence json.RawMessage, ) error
FailPermanent dead-letters immediately: a permanent error means the identical retry would fail identically, so the remaining attempt budget is worthless (and, for agent tasks, expensive). The failing attempt is still counted. Facts: task.failed + task.dead-lettered with class "permanent".
func (*Store) Heartbeat ¶
func (s *Store) Heartbeat(ctx context.Context, id task.ID, owner string, extend time.Duration) error
Heartbeat extends the lease of a Running task held by owner.
func (*Store) ListWatermarks ¶
ListWatermarks returns every consumer cursor, by consumer name — the admin read behind `tq watermarks show`.
func (*Store) MarkOrphaned ¶
MarkOrphaned appends one task.orphaned fact per stranded Running task (lease expired before the cutoff, no orphaned fact yet). Observation only: the task stays Running until a reclaim; the fact explains why it is stranded (worker died, pool down). Idempotent per task.
func (*Store) ProjectCounts ¶
ProjectCounts counts tasks per project per status in one GROUP BY.
func (*Store) Requeue ¶
func (s *Store) Requeue( ctx context.Context, id task.ID, owner string, errText string, delay time.Duration, ) error
Requeue returns a claimed task to Pending without counting an attempt: the executor refused to start (preflight), so the task itself is fine and the environment is expected to become ready later. Claimable again after delay. Fact: task.requeued.
func (*Store) RescueDead ¶
RescueDead re-queues a Dead task with a fresh attempt budget (DLQ rescue).
func (*Store) SaveWatermark ¶
SaveWatermark checkpoints a consumer cursor as a monotonic upsert: the stored seq never regresses, so a lagging or misconfigured second process cannot drag a consumer backwards. Checkpointing is consumer progress, not task state, so no fact is appended.
func (*Store) SetWatermark ¶
SetWatermark overwrites a consumer cursor unconditionally — the ops rescue hatch behind `tq watermarks set`. Unlike SaveWatermark it MAY move the cursor backwards: a rewind forces replay, and downstream idempotency keys (seq-derived) make replay safe. It deliberately bypasses the monotonic runtime guard; use it knowing that.
func (*Store) StatusCounts ¶
StatusCounts counts tasks per status in one GROUP BY.
type StoreOption ¶
type StoreOption func(*storeOptions)
StoreOption configures optional Store behavior.
func WithProjectExclusivity ¶
func WithProjectExclusivity() StoreOption
WithProjectExclusivity turns on store-level per-project serialization: ClaimDue will not claim a task whose project already has another running task — across ALL pools and processes sharing the same database file, not just within one pool. This is the per-repo guarantee for agent pools: two agents never work the same repo simultaneously. Every pool sharing the DB must opt in; pools that do not opt in ignore the guard. Tasks with an empty project are exempt (they are not tied to a repo).