state

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package state is the SQLite state store — schema v1. The store is the system of record: every paging Event corresponds to a durable state change written here first. There is no migration path from the Python schema; existing deployments start cold and re-baseline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptedDigest

type AcceptedDigest struct {
	Key    Key
	Digest string
}

AcceptedDigest pairs a Key with its accepted Baseline digest.

type Attempt

type Attempt struct {
	// ID is the audit trail's own order. It is the cursor `ripen audit`
	// pages by, and it never appears in the JSON surface.
	ID          int64
	Key         Key
	RunID       string
	Actor       domain.Actor
	OldDigest   string
	NewDigest   string
	Result      domain.ResultCode
	Detail      string
	AttemptedAt time.Time
}

Attempt is one recorded Transaction attempt.

type AuditFilter

type AuditFilter struct {
	Limit   int
	Cursor  int64 // page for attempts older than this id
	RunID   string
	Backend domain.Backend
	Stack   string
	Service string
	Result  domain.ResultCode
}

AuditFilter narrows and pages the audit trail. Every field is optional; an empty filter reads the newest attempts.

type CandidateObservation

type CandidateObservation struct {
	Digest    string
	FirstSeen time.Time
	LastSeen  time.Time
	Count     int
}

CandidateObservation is one observed Candidate digest and its history.

type CandidateRecord

type CandidateRecord struct {
	Key       Key
	Digest    string
	FirstSeen time.Time
	LastSeen  time.Time
	Count     int
}

CandidateRecord is one observed Candidate, with its Key.

type Key

type Key struct {
	Backend domain.Backend
	Stack   string
	Service string
}

Key identifies one Service's state: backend, stack, and service, with service empty for a stack-level policy. The Python schema's state_key column pretended this was one string; schema v1 stores the three parts.

type NotifierHealth

type NotifierHealth struct {
	LastSuccessAt       *time.Time
	ConsecutiveFailures int
}

NotifierHealth is the persisted Notifier delivery health.

type PendingProposal

type PendingProposal struct {
	Digest     string
	URL        string
	ProposedAt time.Time
}

PendingProposal is an open Proposal (PR) awaiting review.

type ProposalRecord

type ProposalRecord struct {
	Key    Key
	Digest string
	URL    string
}

ProposalRecord pairs a Key with its pending Proposal for Status.

type Status

type Status struct {
	BreakerOpen      bool
	BreakerReason    string
	AcceptedDigests  []AcceptedDigest
	LeaseActive      bool
	PendingProposals []ProposalRecord
}

Status is the durable state snapshot behind `ripen status`.

type Store

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

Store is the SQLite-backed state store.

func Open

func Open(path string) (*Store, error)

Open opens (creating if needed) the state database at path, creating the parent directory when missing.

func (*Store) AcceptedDigest

func (s *Store) AcceptedDigest(key Key) (string, bool, error)

AcceptedDigest returns the accepted Baseline digest for a Key.

func (*Store) AcquireLease

func (s *Store) AcquireLease(now time.Time, ttlSeconds int) (string, bool, error)

AcquireLease takes the run lease when no unexpired lease exists, returning an owner token. BEGIN IMMEDIATE serializes contenders.

func (*Store) Attempts

func (s *Store) Attempts(limit int) ([]Attempt, error)

Attempts returns the newest attempts, most recent first.

func (*Store) AuditPage

func (s *Store) AuditPage(filter AuditFilter) ([]Attempt, error)

AuditPage reads the audit trail newest first, narrowed by the filter and paged by attempt id. The audit trail is the attempts table — never the Event stream, which is a notification channel and not a record.

func (*Store) Candidate

func (s *Store) Candidate(key Key) (*CandidateRecord, error)

Candidate returns one Key's observed Candidate, or nil.

func (*Store) Candidates

func (s *Store) Candidates() ([]CandidateRecord, error)

Candidates returns every observed Candidate, oldest Key first.

func (*Store) ClearBreaker

func (s *Store) ClearBreaker(reason string, now time.Time) error

ClearBreaker closes the Circuit breaker; the operator's reason is mandatory and recorded.

func (*Store) ClearPendingProposal

func (s *Store) ClearPendingProposal(key Key) (bool, error)

ClearPendingProposal removes a Key's Proposal record, reporting whether one existed.

func (*Store) ClearSuppression

func (s *Store) ClearSuppression(event, stack, service string) error

ClearSuppression drops one suppression key, re-arming it. Recovery uses this: a stack that failed, recovered, and fails again must page the second time.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database handle.

func (*Store) LastAttempt

func (s *Store) LastAttempt(key Key) (*Attempt, error)

LastAttempt returns the newest audit entry for one Key, or nil. The Key is matched exactly, empty service included, which is why this does not go through the audit filter.

func (*Store) NotifierDestination

func (s *Store) NotifierDestination() (string, error)

NotifierDestination reads the fingerprint of the destination the suppression table was built against.

func (*Store) NotifierHealth

func (s *Store) NotifierHealth() (NotifierHealth, error)

NotifierHealth reads the persisted Notifier delivery health.

func (*Store) ObserveCandidate

func (s *Store) ObserveCandidate(key Key, digest string, now time.Time) (CandidateObservation, error)

ObserveCandidate records one observation of a Candidate digest. A new digest replaces any previous Candidate for the Key; re-observing the same digest increments its count, preserving first_seen.

func (*Store) OpenBreaker

func (s *Store) OpenBreaker(reason string, now time.Time) error

OpenBreaker opens the Circuit breaker with a reason.

func (*Store) PendingProposal

func (s *Store) PendingProposal(key Key) (*PendingProposal, error)

PendingProposal returns the Key's open Proposal, or nil.

func (*Store) RecordAttempt

func (s *Store) RecordAttempt(attempt Attempt, now time.Time) error

RecordAttempt appends one Transaction attempt to the audit trail.

func (*Store) RecordNotifierFailure

func (s *Store) RecordNotifierFailure() error

RecordNotifierFailure increments the persisted failure streak.

func (*Store) RecordNotifierSuccess

func (s *Store) RecordNotifierSuccess(now time.Time) error

RecordNotifierSuccess records a successful delivery, resetting the failure streak.

func (*Store) ReleaseLease

func (s *Store) ReleaseLease(token string) error

ReleaseLease releases the lease if the token still owns it; releasing a superseded token is a no-op.

func (*Store) ResetSuppression

func (s *Store) ResetSuppression() error

ResetSuppression clears every suppression record — used when the webhook destination changes, so the new destination pages current state once (which is correct).

func (*Store) SetAcceptedDigest

func (s *Store) SetAcceptedDigest(key Key, digest string, now time.Time) error

SetAcceptedDigest records a digest as the accepted Baseline and clears the Key's Candidates and pending Proposal: accepting is the terminal state of both.

func (*Store) SetNotifierDestination

func (s *Store) SetNotifierDestination(fingerprint string) error

SetNotifierDestination records which destination the suppression table belongs to.

func (*Store) SetPendingProposal

func (s *Store) SetPendingProposal(key Key, digest, proposalURL string, now time.Time) error

SetPendingProposal records an open Proposal for a Key.

func (*Store) SetSuppressionState

func (s *Store) SetSuppressionState(event, stack, service, state string, now time.Time) error

SetSuppressionState records the state a notification was last sent for.

func (*Store) Status

func (s *Store) Status(now time.Time) (Status, error)

Status reads the durable state snapshot.

func (*Store) SuppressionState

func (s *Store) SuppressionState(event, stack, service string) (string, bool, error)

SuppressionState reads the last notified state for a suppression key.

Jump to

Keyboard shortcuts

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