engine

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine is the one engine per machine: it holds the machine's lock, serves the local API on its socket, and exits when nothing is pending or when asked to stop. It never judges.

Index

Constants

View Source
const DefaultIdle = 30 * time.Minute

DefaultIdle is how long the engine waits with nothing pending before it exits, when Options.Idle is not set.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, o Options) error

Run is the engine: it takes the machine's lock, serves the API on the socket, opens the registered repos off the start path, and returns once ctx ends, engine.stop is called, or nothing was pending for the idle duration. Each of those returns nil. Another engine holding the lock returns *RunningError.

Types

type EventOut

type EventOut struct {
	At      string          `json:"at" desc:"When the event was appended, RFC 3339 in UTC."`
	Kind    string          `json:"kind" desc:"What happened, such as intent.done."`
	Subject string          `json:"subject" desc:"What it happened to, such as intent."`
	Person  string          `json:"person,omitempty" desc:"Who made the change; left out when no person did."`
	Data    json.RawMessage `json:"data" desc:"The event's details, a JSON object."`
}

EventOut is one event of engine.events's output.

type EventsInput

type EventsInput struct {
	Repo  string `json:"repo" desc:"The repo, as an absolute path to it or to a directory inside it."`
	Limit int    `json:"limit,omitempty" desc:"How many of the newest events to return: 1 to 500, 50 when left out."`
}

EventsInput is engine.events's input.

type Options

type Options struct {
	Dir     string        // the settings directory, absolute
	Idle    time.Duration // how long to wait with nothing pending; ≤ 0 means DefaultIdle
	Version string        // the version engine.status reports
	State   state.Options // kinds (and in tests a clock) for every repo; StoreDir is set per repo
	// Methods (nil by default) is how tests add methods; get opens a repo's state.
	Methods func(get func(ctx context.Context, repo string) (*state.State, error)) []api.Method
}

Options say how Run serves.

type Paths

type Paths struct {
	Dir    string // the settings directory, mode 0700
	Socket string // the API's Unix socket, mode 0600
	Lock   string // held while the engine runs; holds its pid as text
	Log    string // where a detached engine's output goes
}

Paths are the engine's files in its directory.

func PathsIn

func PathsIn(dir string) (Paths, error)

PathsIn returns the engine's files in dir, which must be absolute. A socket path of 104 bytes or more is refused, naming the path and the limit: no other directory is tried.

type RunningError

type RunningError struct {
	PID int // the running engine's pid; 0 when it has not written it yet
}

RunningError is Run's error when another engine holds the lock.

func (*RunningError) Error

func (e *RunningError) Error() string

type Status

type Status struct {
	Version     string   `json:"version" desc:"The Physa version the engine runs."`
	PID         int      `json:"pid" desc:"The engine's OS process id."`
	StartedAt   string   `json:"started_at" desc:"When the engine started, RFC 3339 in UTC."`
	APIRevision int      `json:"api_revision" desc:"The API revision the engine serves."`
	Repos       []string `json:"repos" desc:"The repos the engine has open."`
}

Status is engine.status's output.

Jump to

Keyboard shortcuts

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