procreg

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package procreg is the saved worker registry (ADR-0167): the process driver and the dev catalog engine record every process they start, so the next open reaps what a crashed run left behind. An entry is reaped only when the live pid's start time and argv both match it, so a reused pid is never signalled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Owned

func Owned(e Entry) bool

Owned reports whether e's pid still names the process its owner started: the start time matches and some argv element contains the token. Any read error means "not ours".

func StartTime

func StartTime(pid int) (uint64, error)

StartTime reads the OS start time of pid, which an owner records right after it starts a process.

Types

type Entry

type Entry struct {
	ID        string   `json:"id"`
	PID       int      `json:"pid"`
	PGID      int      `json:"pgid"`
	StartTime uint64   `json:"startTime"` // OS-native: clock ticks since boot (Linux), µs since epoch (macOS)
	Token     string   `json:"token"`     // substring of one argv element: "--funcd-instance=<id>" or "funcd-engine-<id>"
	Files     []string `json:"files"`     // driver-owned temp files deleted at reap
}

Entry is one process a registry owner started.

type Registry

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

Registry is the saved set of entries in <dir>/<name>.json, owned by one process through the lock on <dir>/<name>.lock. It has no mutex of its own: the caller serializes Put, Delete and Close.

func Open

func Open(dir, name string) (*Registry, error)

Open takes the registry at <dir>/<name>.json, creating dir, and loads its entries. It fails with fault.Conflict while another owner holds the lock.

func (*Registry) Close

func (r *Registry) Close() error

Close empties the registry and releases the lock; a second Close does nothing.

func (*Registry) Delete

func (r *Registry) Delete(id string) error

Delete forgets the entry with id.

func (*Registry) Put

func (r *Registry) Put(e Entry) error

Put records e, replacing the entry with its ID.

func (*Registry) Reap

func (r *Registry) Reap(ctx context.Context, grace time.Duration) (killed int, err error)

Reap ends every saved process that is still ours: SIGTERM to each owned process group, up to grace for all of them together, then SIGKILL to the ones still alive. It deletes every entry's files, owned or not, and empties the registry. killed counts the process groups it signalled.

Jump to

Keyboard shortcuts

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