commit before applying 2p patch
This commit is contained in:
parent
4c33b5dd0e
commit
70faf517f3
@ -27,6 +27,7 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
|
||||
Identified: i.Identified,
|
||||
Implementation: i.Implementation,
|
||||
NextFetch: i.NextFetch,
|
||||
LastError: i.LastError,
|
||||
NodeInfoURL: i.NodeInfoURL,
|
||||
ServerImplementationString: i.ServerImplementationString,
|
||||
ServerVersionString: i.ServerVersionString,
|
||||
@ -49,6 +50,7 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
|
||||
ei.Fetching = i.Fetching
|
||||
ei.HighestID = i.HighestID
|
||||
ei.Hostname = i.Hostname
|
||||
ei.LastError = i.LastError
|
||||
ei.Identified = i.Identified
|
||||
ei.Implementation = string(i.Implementation)
|
||||
ei.NextFetch = i.NextFetch
|
||||
@ -56,7 +58,6 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
|
||||
ei.ServerImplementationString = i.ServerImplementationString
|
||||
ei.ServerVersionString = i.ServerVersionString
|
||||
ei.SuccessCount = i.SuccessCount
|
||||
|
||||
r := m.db.Save(&ei)
|
||||
return r.Error
|
||||
}
|
||||
@ -77,6 +78,7 @@ func (m *Manager) ListInstances() ([]*instance.Instance, error) {
|
||||
x.Fetching = i.Fetching
|
||||
x.HighestID = i.HighestID
|
||||
x.Hostname = i.Hostname
|
||||
x.LastError = i.LastError
|
||||
x.Identified = i.Identified
|
||||
x.Implementation = i.Implementation
|
||||
x.NextFetch = i.NextFetch
|
||||
|
@ -21,7 +21,7 @@ type StoredToot struct {
|
||||
Content []byte
|
||||
TextContent []byte
|
||||
URL string
|
||||
Hostname string
|
||||
Hostname string `gorm:"index:hostnameindex"`
|
||||
}
|
||||
|
||||
type APInstance struct {
|
||||
@ -34,6 +34,7 @@ type APInstance struct {
|
||||
Identified bool
|
||||
Fetching bool
|
||||
Disabled bool
|
||||
LastError string
|
||||
Implementation string
|
||||
NextFetch time.Time
|
||||
NodeInfoURL string
|
||||
|
24
database/readshortcuts.go
Normal file
24
database/readshortcuts.go
Normal file
@ -0,0 +1,24 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (m *Manager) TootCountForHostname(hostname string) (uint, error) {
|
||||
var c uint
|
||||
e := m.db.Model(&StoredToot{}).Where("hostname = ?", hostname).Count(&c)
|
||||
if e.Error != nil {
|
||||
return 0, e.Error
|
||||
} else {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) GetAPInstanceFromUUID(uuid *uuid.UUID) (*APInstance, error) {
|
||||
var i APInstance
|
||||
e := m.db.Model(&APInstance{}).Where("uuid = ?", uuid).First(&i)
|
||||
if e.Error != nil {
|
||||
return nil, e.Error
|
||||
}
|
||||
return &i, nil
|
||||
}
|
@ -37,6 +37,7 @@ type Instance struct {
|
||||
Implementation string
|
||||
InitialFSMState string
|
||||
NextFetch time.Time
|
||||
LastError string
|
||||
NodeInfoURL string
|
||||
ServerImplementationString string
|
||||
ServerVersionString string
|
||||
|
@ -20,15 +20,19 @@ func (a *Server) instances() []hash {
|
||||
now := time.Now()
|
||||
for _, v := range a.feta.manager.ListInstances() {
|
||||
i := make(hash)
|
||||
// TODO move this locking onto a method on Instance that just
|
||||
// returns a new hash
|
||||
// FIXME figure out why a very short lock here deadlocks
|
||||
v.Lock()
|
||||
i["hostname"] = v.Hostname
|
||||
i["uuid"] = v.UUID.String()
|
||||
i["nextCheck"] = v.NextFetch.UTC().Format(time.RFC3339)
|
||||
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
|
||||
i["successCount"] = v.SuccessCount
|
||||
i["errorCount"] = v.ErrorCount
|
||||
i["identified"] = v.Identified
|
||||
i["status"] = v.Status() //FIXME maybe this is why
|
||||
//this only locks the FSM, not the whole instance struct
|
||||
i["status"] = v.Status()
|
||||
i["software"] = "unknown"
|
||||
i["version"] = "unknown"
|
||||
if v.Identified {
|
||||
@ -38,6 +42,14 @@ func (a *Server) instances() []hash {
|
||||
v.Unlock()
|
||||
resp = append(resp, i)
|
||||
}
|
||||
|
||||
for _, item := range resp {
|
||||
count, err := a.feta.dbm.TootCountForHostname(item["hostname"].(string))
|
||||
item["tootCount"] = 0
|
||||
if err != nil {
|
||||
item["tootCount"] = count
|
||||
}
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
@ -75,10 +87,27 @@ func (a *Server) getInstanceListHandler() http.HandlerFunc {
|
||||
}
|
||||
*/
|
||||
|
||||
func (a *Server) instanceHandler(c echo.Context) error {
|
||||
tu := c.Param("uuid")
|
||||
u, err := uuid.Parse(tu)
|
||||
if err != nil {
|
||||
return c.String(http.StatusNotFound, "404 not found")
|
||||
}
|
||||
|
||||
|
||||
i := a.feta.manager.ListInstances() {
|
||||
tc := pongo2.Context{
|
||||
"instance": i,
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "instance.html", tc)
|
||||
}
|
||||
|
||||
func (a *Server) indexHandler(c echo.Context) error {
|
||||
tc := pongo2.Context{
|
||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"gitrev": a.feta.version,
|
||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"gitrev": a.feta.version,
|
||||
"instances": a.instances(),
|
||||
}
|
||||
return c.Render(http.StatusOK, "index.html", tc)
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ func (s *Server) initRouter() {
|
||||
|
||||
// Routes
|
||||
s.e.GET("/", s.indexHandler)
|
||||
s.e.GET("/instance/:uuid", s.instanceHandler)
|
||||
s.e.GET("/stats.json", s.statsHandler)
|
||||
s.e.GET("/.well-known/healthcheck.json", s.healthCheckHandler)
|
||||
//a.e.GET("/about", s.aboutHandler)
|
||||
|
@ -10,6 +10,7 @@
|
||||
<meta name="author" content="">
|
||||
-->
|
||||
<title>{{ htmltitle }}</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" integrity="sha384-Bfad6CLCknfcloXFOyFnlgtENryhrpZCe29RTifKEixXQZ38WheV+i/6YWSzkz3V" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
|
||||
<style>
|
||||
|
@ -9,17 +9,25 @@
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col">Key</th>
|
||||
<th scope="col">Value</th>
|
||||
<th scope="col">instance id</th>
|
||||
<th scope="col">hostname</th>
|
||||
<th scope="col">status</th>
|
||||
<th scope="col">tootCount</th>
|
||||
<th scope="col">Detail</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for stat in stats %}
|
||||
{% for instance in instances %}
|
||||
<tr>
|
||||
{{stat.key}}
|
||||
</tr>
|
||||
<tr>
|
||||
{{stat.value}}
|
||||
<td><a href="/instance/{{instance.uuid}}">{{instance.uuid}}</a></td>
|
||||
<td><a href="https://{{instance.hostname}}">{{instance.hostname}}</a></td>
|
||||
<td>{{instance.status}}</td>
|
||||
<td>{{instance.tootCount}}</td>
|
||||
<td><a
|
||||
href="/instance/{{instance.uuid}}"
|
||||
class="btn btn-info">
|
||||
<i class="fab fa-mastodon"></i>
|
||||
</button></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user