still builds

master
Jeffrey Paul 4 years ago
parent 0683cd7b32
commit 84b19fb14e
  1. 12
      database/dbmodel.go
  2. 4
      database/manager.go
  3. 13
      manager/manager.go

@ -3,6 +3,7 @@ package database
import (
"time"
"git.eeqj.de/sneak/feta/instance"
"github.com/google/uuid"
"github.com/jinzhu/gorm"
@ -12,12 +13,12 @@ import (
// NB that when you add a model below you must add it to this list!
func (m *Manager) doMigrations() {
m.db.AutoMigrate(&instance{})
m.db.AutoMigrate(&apinstance{})
}
type instance struct {
type apinstance struct {
gorm.Model
Identifier uuid.UUID
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
ErrorCount uint
SuccessCount uint
HighestID int
@ -32,6 +33,9 @@ type instance struct {
ServerImplementationString string
}
func (m *Manager) ListInstances() {
func (m *Manager) ListInstances() ([]*instance.Instance, error) {
output := make([]*instance.Instance, 0)
// FIXME have this produce a list of Instance
return output, nil
}

@ -23,6 +23,10 @@ func New() *Manager {
}
func (m *Manager) init() {
m.db.LogMode(false)
if viper.GetBool("Debug") {
m.db.LogMode(true)
}
m.open()
}

@ -11,16 +11,17 @@ import (
"github.com/spf13/viper"
)
//import "github.com/gin-gonic/gin"
// LogReportInterval defines how long between logging internal
// stats/reporting for user supervision
var LogReportInterval = time.Second * 10
// conform for storing toots
type DatabaseStorage interface {
ListInstances() ([]*instance.Instance, error)
StoreInstances([]*instance.Instance) error
}
// InstanceManager is the main data structure for the goroutine that manages
// the list of all known instances, fed by the locator
type InstanceManager struct {
mu sync.Mutex
db DatabaseStorage
instances map[instance.Hostname]*instance.Instance
newInstanceNotifications chan instance.Hostname
tootDestination chan *toot.Toot
@ -89,7 +90,7 @@ func (im *InstanceManager) Manage() {
log.Info().Msg("InstanceManager tick")
im.managerLoop()
time.Sleep(1 * time.Second)
if time.Now().After(x.Add(LogReportInterval)) {
if time.Now().After(x.Add(viper.GetDuration("LogReportInterval"))) {
x = time.Now()
im.logInstanceReport()
}

Loading…
Cancel
Save