Add a metadata system
This commit is contained in:
parent
07409a01be
commit
8b3218ad00
16 changed files with 365 additions and 61 deletions
|
|
@ -3,15 +3,17 @@ package instances
|
|||
import (
|
||||
"embed"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
//go:embed all:instances/barrel instances/barrel.env
|
||||
var barrelResources embed.FS
|
||||
|
||||
// Barrel returns a stack representing the running WissKI Instance
|
||||
func (wisski WissKI) Barrel() component.StackWithResources {
|
||||
func (wisski *WissKI) Barrel() component.StackWithResources {
|
||||
return component.StackWithResources{
|
||||
Stack: component.Stack{
|
||||
Dir: wisski.FilesystemBase,
|
||||
|
|
@ -43,11 +45,59 @@ func (wisski WissKI) Barrel() component.StackWithResources {
|
|||
}
|
||||
}
|
||||
|
||||
const KeyLastRebuild MetaKey = "lastRebuild"
|
||||
|
||||
func (wisski *WissKI) LastRebuild() (t time.Time, err error) {
|
||||
var epoch int64
|
||||
|
||||
// read the epoch!
|
||||
err = wisski.Metadata().Get(KeyLastRebuild, &epoch)
|
||||
if err == ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
// and turn it into time!
|
||||
return time.Unix(epoch, 0), nil
|
||||
}
|
||||
|
||||
func (wisski *WissKI) setLastRebuild() error {
|
||||
return wisski.Metadata().Set(KeyLastRebuild, time.Now().Unix())
|
||||
}
|
||||
|
||||
// Build builds or rebuilds the barel connected to this instance.
|
||||
//
|
||||
// It also logs the current time into the metadata belonging to this instance.
|
||||
func (wisski *WissKI) Build(stream stream.IOStream, start bool) error {
|
||||
barrel := wisski.Barrel()
|
||||
|
||||
var context component.InstallationContext
|
||||
|
||||
{
|
||||
err := barrel.Install(stream, context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
err := barrel.Update(stream, start)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// store the current last rebuild
|
||||
return wisski.setLastRebuild()
|
||||
}
|
||||
|
||||
//go:embed all:instances/reserve instances/reserve.env
|
||||
var reserveResources embed.FS
|
||||
|
||||
// Reserve returns a stack representing the reserve instance
|
||||
func (wisski WissKI) Reserve() component.StackWithResources {
|
||||
func (wisski *WissKI) Reserve() component.StackWithResources {
|
||||
return component.StackWithResources{
|
||||
Stack: component.Stack{
|
||||
Dir: wisski.FilesystemBase,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue