diff --git a/database/dbmodel.go b/database/dbmodel.go index cc818b4..ed9651d 100644 --- a/database/dbmodel.go +++ b/database/dbmodel.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 } diff --git a/database/manager.go b/database/manager.go index b3149f3..1ec2fa2 100644 --- a/database/manager.go +++ b/database/manager.go @@ -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() } diff --git a/manager/manager.go b/manager/manager.go index c379111..e37183a 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -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() }