localstate

package
v0.5.30-beta Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package localstate stores runner identity, registrations, and workspace locks outside source repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalWorkspace

func CanonicalWorkspace(path string) (string, error)

CanonicalWorkspace resolves an existing workspace to a stable absolute path.

Types

type HostIdentity

type HostIdentity struct {
	Version    int       `json:"version"`
	InstanceID string    `json:"instanceId"`
	CreatedAt  time.Time `json:"createdAt"`
}

HostIdentity is the stable, non-secret identifier for one local Kodelet installation.

type LockHeldError

type LockHeldError struct {
	Path     string
	Metadata LockMetadata
}

LockHeldError reports diagnostics from an already-running workspace runner.

func (*LockHeldError) Error

func (e *LockHeldError) Error() string

type LockMetadata

type LockMetadata struct {
	Version     int        `json:"version"`
	PID         int        `json:"pid"`
	Hostname    string     `json:"hostname"`
	Workspace   string     `json:"workspace"`
	Server      string     `json:"server"`
	RunnerID    string     `json:"runnerId,omitempty"`
	DisplayName string     `json:"displayName,omitempty"`
	StartedAt   time.Time  `json:"startedAt"`
	StoppedAt   *time.Time `json:"stoppedAt,omitempty"`
}

LockMetadata is diagnostic process information stored in the advisory lock file.

type Registration

type Registration struct {
	Version     int       `json:"version"`
	Server      string    `json:"server"`
	Workspace   string    `json:"workspace"`
	RunnerID    string    `json:"runnerId"`
	DisplayName string    `json:"displayName,omitempty"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

Registration caches one control-plane-assigned runner identity for a host workspace.

type Store

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

Store owns runner-local state rooted below the Kodelet user-state directory.

func NewStore

func NewStore() (*Store, error)

NewStore opens the default runner-local state directory.

func NewStoreAt

func NewStoreAt(root string) (*Store, error)

NewStoreAt opens a runner-local state directory at an explicit path.

func (*Store) AcquireWorkspaceLock

func (s *Store) AcquireWorkspaceLock(workspace string, metadata LockMetadata) (*WorkspaceLock, error)

AcquireWorkspaceLock acquires the non-blocking advisory lock for a canonical workspace.

func (*Store) DeleteRegistration

func (s *Store) DeleteRegistration(server, workspace, expectedRunnerID string) (bool, error)

DeleteRegistration removes a cached registration only when it still contains the expected runner ID.

func (*Store) LoadOrCreateHostIdentity

func (s *Store) LoadOrCreateHostIdentity() (HostIdentity, error)

LoadOrCreateHostIdentity returns the stable host instance ID, creating it atomically when absent.

func (*Store) LoadRegistration

func (s *Store) LoadRegistration(server, workspace string) (Registration, bool, error)

LoadRegistration returns a cached stable runner ID for a server and canonical workspace.

func (*Store) ReadWorkspaceLockMetadata

func (s *Store) ReadWorkspaceLockMetadata(workspace string) (LockMetadata, bool, error)

ReadWorkspaceLockMetadata reads the latest diagnostic lock metadata without acquiring the lock.

func (*Store) Registrations

func (s *Store) Registrations() ([]Registration, error)

Registrations lists every locally cached control-plane registration.

func (*Store) Root

func (s *Store) Root() string

Root returns the runner-local state directory.

func (*Store) SaveRegistration

func (s *Store) SaveRegistration(registration Registration) error

SaveRegistration atomically updates a cached stable runner ID.

func (*Store) WorkspaceLockHeld

func (s *Store) WorkspaceLockHeld(workspace string) (bool, error)

WorkspaceLockHeld reports whether another open file description currently owns the advisory lock for a workspace. A stale diagnostic file without a live lock returns false.

func (*Store) WorkspaceLockPath

func (s *Store) WorkspaceLockPath(workspace string) string

WorkspaceLockPath returns the diagnostic lock-file path for a canonical workspace.

type WorkspaceLock

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

WorkspaceLock holds the OS-level advisory lock for one canonical workspace.

func (*WorkspaceLock) Close

func (l *WorkspaceLock) Close() error

Close records a stop time and releases the advisory lock.

func (*WorkspaceLock) Metadata

func (l *WorkspaceLock) Metadata() LockMetadata

Metadata returns the latest metadata written by this process.

func (*WorkspaceLock) Path

func (l *WorkspaceLock) Path() string

Path returns the diagnostic lock-file path.

func (*WorkspaceLock) WriteMetadata

func (l *WorkspaceLock) WriteMetadata(metadata LockMetadata) error

WriteMetadata updates the diagnostic JSON while retaining the advisory lock.

Jump to

Keyboard shortcuts

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