Update Info() behavior

This commit is contained in:
Tom Wiesing 2022-09-26 16:10:25 +02:00
parent 72d95f58ea
commit 196555e897
No known key found for this signature in database
4 changed files with 36 additions and 28 deletions

View file

@ -25,9 +25,9 @@ func New(io stream.IOStream, dis *wisski.Distillery, description Description) (b
// do the create keeping track of time!
logging.LogOperation(func() error {
backup.StartTime = time.Now()
backup.StartTime = time.Now().UTC()
backup.run(io, dis)
backup.EndTime = time.Now()
backup.EndTime = time.Now().UTC()
return nil
}, io, "Writing backup files")

View file

@ -62,7 +62,7 @@ type disIndex struct {
Config *config.Config
Instances []instances.Info
Instances []instances.WissKIInfo
TotalCount int
RunningCount int
StoppedCount int
@ -89,7 +89,7 @@ func (dis *Control) disIndex(r *http.Request) (idx disIndex, err error) {
idx.Config = dis.Config
// current time
idx.Time = time.Now()
idx.Time = time.Now().UTC()
return
}
@ -99,7 +99,7 @@ type disInstance struct {
Time time.Time
Instance models.Instance
Info instances.Info
Info instances.WissKIInfo
}
func (dis *Control) disInstance(r *http.Request) (is disInstance, err error) {
@ -124,7 +124,7 @@ func (dis *Control) disInstance(r *http.Request) (is disInstance, err error) {
}
// current time
is.Time = time.Now()
is.Time = time.Now().UTC()
return
}
@ -149,7 +149,7 @@ var indexTemplate = template.Must(template.New("index.html").Parse(indexTemplate
var instanceTemplateString string
var instanceTemplate = template.Must(template.New("instance.html").Parse(instanceTemplateString))
func (dis *Control) getinstance(r *http.Request) (info instances.Info, err error) {
func (dis *Control) getinstance(r *http.Request) (info instances.WissKIInfo, err error) {
// find the slug as the last component of path!
slug := strings.TrimSuffix(r.URL.Path, "/")
slug = slug[strings.LastIndex(slug, "/")+1:]
@ -167,7 +167,7 @@ func (dis *Control) getinstance(r *http.Request) (info instances.Info, err error
return wisski.Info(false)
}
func (dis *Control) allinstances(*http.Request) (infos []instances.Info, err error) {
func (dis *Control) allinstances(*http.Request) (infos []instances.WissKIInfo, err error) {
var errgroup errgroup.Group
// list all the instances
@ -177,7 +177,7 @@ func (dis *Control) allinstances(*http.Request) (infos []instances.Info, err err
}
// get all of their info!
infos = make([]instances.Info, len(all))
infos = make([]instances.WissKIInfo, len(all))
for i, instance := range all {
{
i := i

View file

@ -8,21 +8,29 @@ import (
"golang.org/x/sync/errgroup"
)
// Info represents some info about this WissKI
type Info struct {
Slug string // The slug of the instance
URL string // The public URL of this instance
// WissKIInfo represents information about this WissKI Instance.
type WissKIInfo struct {
Time time.Time // Time this info was built
// Generic Information
Slug string // slug
URL string // complete URL, including http(s)
// Information about the running instance
Running bool
LastRebuild time.Time
Running bool // is the instance running?
Pathbuilders map[string]string // list of pathbuilders
Prefixes []string // list of uri prefixes
// WissKI content information
Prefixes []string // list of prefixes
Pathbuilders map[string]string // all the pathbuilders
}
// Info returns information about this WissKI instance.
func (wisski *WissKI) Info(quick bool) (info Info, err error) {
fmt.Println("call to info")
// Info generate a
func (wisski *WissKI) Info(quick bool) (info WissKIInfo, err error) {
// TODO: Cache this, and run it with every cron!
info.Time = time.Now().UTC()
// static properties
info.Slug = wisski.Slug
info.URL = wisski.URL().String()
@ -32,21 +40,21 @@ func (wisski *WissKI) Info(quick bool) (info Info, err error) {
// quick check if this wisski is running
group.Go(func() (err error) {
info.Running, err = wisski.Alive()
info.Running, err = wisski.Running()
return
})
// slower checks for extra properties.
// these might execute php code or require additional database queries.
if !quick {
group.Go(func() error {
info.Pathbuilders, _ = wisski.AllPathbuilders()
return nil
})
group.Go(func() (err error) {
info.LastRebuild, _ = wisski.LastRebuild()
return nil
})
group.Go(func() error {
info.Pathbuilders, _ = wisski.AllPathbuilders()
return nil
})
group.Go(func() (err error) {
info.Prefixes, _ = wisski.Prefixes()
return nil
@ -58,8 +66,8 @@ func (wisski *WissKI) Info(quick bool) (info Info, err error) {
return
}
// Alive checks if this WissKI is currently running.
func (wisski *WissKI) Alive() (bool, error) {
// Running checks if this WissKI is currently running.
func (wisski *WissKI) Running() (bool, error) {
ps, err := wisski.Barrel().Ps(stream.FromNil())
if err != nil {
return false, err

View file

@ -174,12 +174,12 @@ func (dis *Distillery) Snapshot(instance instances.WissKI, io stream.IOStream, d
// do the create keeping track of time!
logging.LogOperation(func() error {
snapshot.StartTime = time.Now()
snapshot.StartTime = time.Now().UTC()
snapshot.makeBlackbox(io, dis, instance)
snapshot.makeWhitebox(io, dis, instance)
snapshot.EndTime = time.Now()
snapshot.EndTime = time.Now().UTC()
return nil
}, io, "Writing snapshot files")