store

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package store is the durable run-history layer: an embedded SQLite database (pure-Go modernc driver) plus a central directory of per-run log files. It is written by the persistence sink during a run and read by the `local-ci runs` / `local-ci log` commands (and later the server/UI).

Index

Constants

View Source
const (
	StatusRunning = "running"
	StatusPassed  = "passed"
	StatusFailed  = "failed"
)

Run statuses.

Variables

View Source
var ErrNotFound = errors.New("run not found")

ErrNotFound is returned by GetRun when no run matches the id.

Functions

func DefaultDBPath

func DefaultDBPath() (string, error)

DefaultDBPath returns the standard database path under the XDG data dir.

Types

type Job

type Job struct {
	ID         int64
	RunID      string
	Name       string
	Stage      string
	ExecKind   string
	GroupLabel string
	Status     string
	StartedAt  time.Time
	FinishedAt time.Time
	Duration   time.Duration
	ExitCode   int
	Error      string
	LogPath    string
}

Job is a persisted job within a run.

type JobSample added in v0.2.3

type JobSample struct {
	RunID     string
	Name      string
	Status    string
	StartedAt time.Time
	Duration  time.Duration
}

JobSample is one job execution inside the recent-runs window, ordered oldest-first — the raw material for duration sparklines and flakiness flags.

type Run

type Run struct {
	ID          string
	ProjectPath string
	ConfigPath  string
	Mode        string
	Status      string
	StartedAt   time.Time
	FinishedAt  time.Time
	Duration    time.Duration
	Error       string
	Commit      string // HEAD SHA at run start ("" outside a git repo)
	Branch      string // branch name at run start
}

Run is a persisted pipeline run. Times are zero and Duration is 0 until the run finishes.

type Store

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

Store wraps the SQLite database and the run-log root directory.

func Open

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

Open opens (creating if needed) the store at dbPath, applying the schema. The parent directory is created quietly; it intentionally does not use fs.MakeDefaultDir, which prints to stdout.

func (*Store) Close

func (s *Store) Close() error

func (*Store) CountRuns added in v0.2.0

func (s *Store) CountRuns(projectPath string, all bool) (int, error)

CountRuns returns the total number of runs (for pagination), scoped to projectPath unless all is true.

func (*Store) CreateRun

func (s *Store) CreateRun(r Run) error

CreateRun inserts a new run row (status should be StatusRunning).

func (*Store) DBPath added in v0.2.0

func (s *Store) DBPath() string

DBPath returns the SQLite database file path.

func (*Store) DeleteRun added in v0.2.0

func (s *Store) DeleteRun(id string) error

DeleteRun removes a run, its job rows, and its on-disk log directory. A missing log directory is not an error.

func (*Store) FinishJob

func (s *Store) FinishJob(id int64, status string, finishedAt time.Time, dur time.Duration, exitCode int, errMsg string) error

FinishJob records a job's terminal status, finish time, duration and exit code.

func (*Store) FinishRun

func (s *Store) FinishRun(id, status string, finishedAt time.Time, dur time.Duration, errMsg string) error

FinishRun records a run's terminal status, finish time and duration.

func (*Store) GetJobs

func (s *Store) GetJobs(runID string) ([]Job, error)

GetJobs returns a run's jobs in insertion order.

func (*Store) GetRun

func (s *Store) GetRun(id string) (Run, error)

GetRun returns a single run by id, or ErrNotFound.

func (*Store) JobSamples added in v0.2.3

func (s *Store) JobSamples(projectPath string, all bool, window int) ([]JobSample, error)

JobSamples returns every job execution from the `window` most recent runs of projectPath (all projects when all is true), ordered oldest run first.

func (*Store) ListRuns

func (s *Store) ListRuns(projectPath string, all bool, limit, offset int) ([]Run, error)

ListRuns returns runs newest first, skipping offset and capped at limit. When all is false the list is restricted to projectPath. limit <= 0 defaults to 20.

func (*Store) OldRunIDs added in v0.2.0

func (s *Store) OldRunIDs(projectPath string, all bool, keep int) ([]string, error)

OldRunIDs returns the ids of every run beyond the keep most recent (newest first), scoped to projectPath unless all is true — the candidates for cleanup.

func (*Store) Root

func (s *Store) Root() string

Root returns the store's base directory (<xdg>/local-ci).

func (*Store) RunDir

func (s *Store) RunDir(id string) string

RunDir returns the directory holding a run's log files.

func (*Store) StartJob

func (s *Store) StartJob(j Job) (int64, error)

StartJob inserts a job row and returns its rowid.

Jump to

Keyboard shortcuts

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