All checks were successful
Test / Create distribution (push) Successful in 1m10s
Test / Sandbox (push) Successful in 2m40s
Test / Hakurei (push) Successful in 3m58s
Test / Hpkg (push) Successful in 4m44s
Test / Sandbox (race detector) (push) Successful in 5m1s
Test / Hakurei (race detector) (push) Successful in 6m2s
Test / Flake checks (push) Successful in 1m47s
This frees all container instances of side effects. Signed-off-by: Ophestra <cat@gensokyo.uk>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Package state provides cross-process state tracking for hakurei container instances.
|
|
package state
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"time"
|
|
|
|
"hakurei.app/hst"
|
|
)
|
|
|
|
var ErrNoConfig = errors.New("state does not contain config")
|
|
|
|
type Entries map[ID]*State
|
|
|
|
type Store interface {
|
|
// Do calls f exactly once and ensures store exclusivity until f returns.
|
|
// Returns whether f is called and any errors during the locking process.
|
|
// Cursor provided to f becomes invalid as soon as f returns.
|
|
Do(identity int, f func(c Cursor)) (ok bool, err error)
|
|
|
|
// List queries the store and returns a list of identities known to the store.
|
|
// Note that some or all returned identities might not have any active apps.
|
|
List() (identities []int, err error)
|
|
|
|
// Close releases any resources held by Store.
|
|
Close() error
|
|
}
|
|
|
|
// Cursor provides access to the store
|
|
type Cursor interface {
|
|
Save(state *State, configWriter io.WriterTo) error
|
|
Destroy(id ID) error
|
|
Load() (Entries, error)
|
|
Len() (int, error)
|
|
}
|
|
|
|
// State is an instance state
|
|
type State struct {
|
|
// hakurei instance id
|
|
ID ID `json:"instance"`
|
|
// child process PID value
|
|
PID int `json:"pid"`
|
|
// sealed app configuration
|
|
Config *hst.Config `json:"config"`
|
|
|
|
// process start time
|
|
Time time.Time `json:"time"`
|
|
}
|