Move wisski instance code to separate package
This commit is contained in:
parent
7c3c84e116
commit
063f3f9b7d
67 changed files with 533 additions and 409 deletions
|
|
@ -1,49 +0,0 @@
|
|||
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())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue