aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/state/state.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-07-03 04:11:38 +0900
committerOphestra <cat@gensokyo.uk>2025-07-03 04:36:59 +0900
commit087959e81bcd52104676ccacedd605e6491b4376 (patch)
tree11cd6eccbfd9278f6c99d33191b320bb4e728888 /internal/app/state/state.go
parente6967b8bbb5ceec3abbd002f52cff1167a969e9e (diff)
app: remove split implementation
It is completely nonsensical and highly error-prone to have multiple implementations of this in the same build. This should be switched at compile time instead therefore the split packages are pointless. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/state/state.go')
-rw-r--r--internal/app/state/state.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/app/state/state.go b/internal/app/state/state.go
new file mode 100644
index 00000000..42750ec6
--- /dev/null
+++ b/internal/app/state/state.go
@@ -0,0 +1,49 @@
+// 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(aid int, f func(c Cursor)) (ok bool, err error)
+
+ // List queries the store and returns a list of aids known to the store.
+ // Note that some or all returned aids might not have any active apps.
+ List() (aids []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"`
+}