Update Info() behavior
This commit is contained in:
parent
72d95f58ea
commit
196555e897
4 changed files with 36 additions and 28 deletions
|
|
@ -25,9 +25,9 @@ func New(io stream.IOStream, dis *wisski.Distillery, description Description) (b
|
||||||
|
|
||||||
// do the create keeping track of time!
|
// do the create keeping track of time!
|
||||||
logging.LogOperation(func() error {
|
logging.LogOperation(func() error {
|
||||||
backup.StartTime = time.Now()
|
backup.StartTime = time.Now().UTC()
|
||||||
backup.run(io, dis)
|
backup.run(io, dis)
|
||||||
backup.EndTime = time.Now()
|
backup.EndTime = time.Now().UTC()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, io, "Writing backup files")
|
}, io, "Writing backup files")
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ type disIndex struct {
|
||||||
|
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
|
|
||||||
Instances []instances.Info
|
Instances []instances.WissKIInfo
|
||||||
TotalCount int
|
TotalCount int
|
||||||
RunningCount int
|
RunningCount int
|
||||||
StoppedCount int
|
StoppedCount int
|
||||||
|
|
@ -89,7 +89,7 @@ func (dis *Control) disIndex(r *http.Request) (idx disIndex, err error) {
|
||||||
idx.Config = dis.Config
|
idx.Config = dis.Config
|
||||||
|
|
||||||
// current time
|
// current time
|
||||||
idx.Time = time.Now()
|
idx.Time = time.Now().UTC()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,7 @@ type disInstance struct {
|
||||||
Time time.Time
|
Time time.Time
|
||||||
|
|
||||||
Instance models.Instance
|
Instance models.Instance
|
||||||
Info instances.Info
|
Info instances.WissKIInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dis *Control) disInstance(r *http.Request) (is disInstance, err error) {
|
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
|
// current time
|
||||||
is.Time = time.Now()
|
is.Time = time.Now().UTC()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +149,7 @@ var indexTemplate = template.Must(template.New("index.html").Parse(indexTemplate
|
||||||
var instanceTemplateString string
|
var instanceTemplateString string
|
||||||
var instanceTemplate = template.Must(template.New("instance.html").Parse(instanceTemplateString))
|
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!
|
// find the slug as the last component of path!
|
||||||
slug := strings.TrimSuffix(r.URL.Path, "/")
|
slug := strings.TrimSuffix(r.URL.Path, "/")
|
||||||
slug = slug[strings.LastIndex(slug, "/")+1:]
|
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)
|
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
|
var errgroup errgroup.Group
|
||||||
|
|
||||||
// list all the instances
|
// list all the instances
|
||||||
|
|
@ -177,7 +177,7 @@ func (dis *Control) allinstances(*http.Request) (infos []instances.Info, err err
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all of their info!
|
// get all of their info!
|
||||||
infos = make([]instances.Info, len(all))
|
infos = make([]instances.WissKIInfo, len(all))
|
||||||
for i, instance := range all {
|
for i, instance := range all {
|
||||||
{
|
{
|
||||||
i := i
|
i := i
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,29 @@ import (
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Info represents some info about this WissKI
|
// WissKIInfo represents information about this WissKI Instance.
|
||||||
type Info struct {
|
type WissKIInfo struct {
|
||||||
Slug string // The slug of the instance
|
Time time.Time // Time this info was built
|
||||||
URL string // The public URL of this instance
|
|
||||||
|
|
||||||
|
// Generic Information
|
||||||
|
Slug string // slug
|
||||||
|
URL string // complete URL, including http(s)
|
||||||
|
|
||||||
|
// Information about the running instance
|
||||||
|
Running bool
|
||||||
LastRebuild time.Time
|
LastRebuild time.Time
|
||||||
|
|
||||||
Running bool // is the instance running?
|
// WissKI content information
|
||||||
Pathbuilders map[string]string // list of pathbuilders
|
Prefixes []string // list of prefixes
|
||||||
Prefixes []string // list of uri prefixes
|
Pathbuilders map[string]string // all the pathbuilders
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info returns information about this WissKI instance.
|
// Info generate a
|
||||||
func (wisski *WissKI) Info(quick bool) (info Info, err error) {
|
func (wisski *WissKI) Info(quick bool) (info WissKIInfo, err error) {
|
||||||
fmt.Println("call to info")
|
// TODO: Cache this, and run it with every cron!
|
||||||
|
|
||||||
|
info.Time = time.Now().UTC()
|
||||||
|
|
||||||
// static properties
|
// static properties
|
||||||
info.Slug = wisski.Slug
|
info.Slug = wisski.Slug
|
||||||
info.URL = wisski.URL().String()
|
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
|
// quick check if this wisski is running
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
info.Running, err = wisski.Alive()
|
info.Running, err = wisski.Running()
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// slower checks for extra properties.
|
// slower checks for extra properties.
|
||||||
// these might execute php code or require additional database queries.
|
// these might execute php code or require additional database queries.
|
||||||
if !quick {
|
if !quick {
|
||||||
group.Go(func() error {
|
|
||||||
info.Pathbuilders, _ = wisski.AllPathbuilders()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
info.LastRebuild, _ = wisski.LastRebuild()
|
info.LastRebuild, _ = wisski.LastRebuild()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
group.Go(func() error {
|
||||||
|
info.Pathbuilders, _ = wisski.AllPathbuilders()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
info.Prefixes, _ = wisski.Prefixes()
|
info.Prefixes, _ = wisski.Prefixes()
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -58,8 +66,8 @@ func (wisski *WissKI) Info(quick bool) (info Info, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alive checks if this WissKI is currently running.
|
// Running checks if this WissKI is currently running.
|
||||||
func (wisski *WissKI) Alive() (bool, error) {
|
func (wisski *WissKI) Running() (bool, error) {
|
||||||
ps, err := wisski.Barrel().Ps(stream.FromNil())
|
ps, err := wisski.Barrel().Ps(stream.FromNil())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,12 @@ func (dis *Distillery) Snapshot(instance instances.WissKI, io stream.IOStream, d
|
||||||
|
|
||||||
// do the create keeping track of time!
|
// do the create keeping track of time!
|
||||||
logging.LogOperation(func() error {
|
logging.LogOperation(func() error {
|
||||||
snapshot.StartTime = time.Now()
|
snapshot.StartTime = time.Now().UTC()
|
||||||
|
|
||||||
snapshot.makeBlackbox(io, dis, instance)
|
snapshot.makeBlackbox(io, dis, instance)
|
||||||
snapshot.makeWhitebox(io, dis, instance)
|
snapshot.makeWhitebox(io, dis, instance)
|
||||||
|
|
||||||
snapshot.EndTime = time.Now()
|
snapshot.EndTime = time.Now().UTC()
|
||||||
return nil
|
return nil
|
||||||
}, io, "Writing snapshot files")
|
}, io, "Writing snapshot files")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue