frontend: Add instance update functionality

This commit is contained in:
Tom Wiesing 2022-10-15 18:14:23 +02:00
parent ccab2883a6
commit 45af2cc95b
No known key found for this signature in database
6 changed files with 119 additions and 70 deletions

View file

@ -21,6 +21,7 @@ type WissKIInfo struct {
// Information about the running instance
Running bool
LastRebuild time.Time
LastUpdate time.Time
// List of backups made
Snapshots []models.Export
@ -63,6 +64,10 @@ func (wisski *WissKI) Info(quick bool) (info WissKIInfo, err error) {
info.LastRebuild, _ = wisski.LastRebuild()
return nil
})
group.Go(func() (err error) {
info.LastUpdate, _ = wisski.LastUpdate()
return nil
})
group.Go(func() error {
info.Pathbuilders, _ = wisski.AllPathbuilders()
return nil

View file

@ -0,0 +1,49 @@
package instances
import (
"time"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/stream"
)
var errBlindUpdateFailed = exit.Error{
Message: "Failed to run blind update script for instance %q: exited with code %s",
ExitCode: exit.ExitGeneric,
}
// BlinUpdate performs a blind update of the given instance
func (wisski *WissKI) BlindUpdate(io stream.IOStream) error {
code, err := wisski.Shell(io, "/runtime/blind_update.sh")
if err != nil {
return errBlindUpdateFailed.WithMessageF(wisski.Slug, environment.ExecCommandError)
}
if code != 0 {
return errBlindUpdateFailed.WithMessageF(wisski.Slug, code)
}
return wisski.setLastUpdate()
}
const KeyLastUpdate MetaKey = "lastUpdate"
func (wisski *WissKI) LastUpdate() (t time.Time, err error) {
var epoch int64
// read the epoch!
err = wisski.Metadata().Get(KeyLastUpdate, &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) setLastUpdate() error {
return wisski.Metadata().Set(KeyLastUpdate, time.Now().Unix())
}