This commit is contained in:
parent
0683cd7b32
commit
84b19fb14e
@ -3,6 +3,7 @@ package database
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.eeqj.de/sneak/feta/instance"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
@ -12,12 +13,12 @@ import (
|
|||||||
// NB that when you add a model below you must add it to this list!
|
// NB that when you add a model below you must add it to this list!
|
||||||
|
|
||||||
func (m *Manager) doMigrations() {
|
func (m *Manager) doMigrations() {
|
||||||
m.db.AutoMigrate(&instance{})
|
m.db.AutoMigrate(&apinstance{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type instance struct {
|
type apinstance struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Identifier uuid.UUID
|
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
||||||
ErrorCount uint
|
ErrorCount uint
|
||||||
SuccessCount uint
|
SuccessCount uint
|
||||||
HighestID int
|
HighestID int
|
||||||
@ -32,6 +33,9 @@ type instance struct {
|
|||||||
ServerImplementationString string
|
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
|
// FIXME have this produce a list of Instance
|
||||||
|
|
||||||
|
return output, nil
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,10 @@ func New() *Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) init() {
|
func (m *Manager) init() {
|
||||||
|
m.db.LogMode(false)
|
||||||
|
if viper.GetBool("Debug") {
|
||||||
|
m.db.LogMode(true)
|
||||||
|
}
|
||||||
m.open()
|
m.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,16 +11,17 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
//import "github.com/gin-gonic/gin"
|
// conform for storing toots
|
||||||
|
type DatabaseStorage interface {
|
||||||
// LogReportInterval defines how long between logging internal
|
ListInstances() ([]*instance.Instance, error)
|
||||||
// stats/reporting for user supervision
|
StoreInstances([]*instance.Instance) error
|
||||||
var LogReportInterval = time.Second * 10
|
}
|
||||||
|
|
||||||
// InstanceManager is the main data structure for the goroutine that manages
|
// InstanceManager is the main data structure for the goroutine that manages
|
||||||
// the list of all known instances, fed by the locator
|
// the list of all known instances, fed by the locator
|
||||||
type InstanceManager struct {
|
type InstanceManager struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
db DatabaseStorage
|
||||||
instances map[instance.Hostname]*instance.Instance
|
instances map[instance.Hostname]*instance.Instance
|
||||||
newInstanceNotifications chan instance.Hostname
|
newInstanceNotifications chan instance.Hostname
|
||||||
tootDestination chan *toot.Toot
|
tootDestination chan *toot.Toot
|
||||||
@ -89,7 +90,7 @@ func (im *InstanceManager) Manage() {
|
|||||||
log.Info().Msg("InstanceManager tick")
|
log.Info().Msg("InstanceManager tick")
|
||||||
im.managerLoop()
|
im.managerLoop()
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
if time.Now().After(x.Add(LogReportInterval)) {
|
if time.Now().After(x.Add(viper.GetDuration("LogReportInterval"))) {
|
||||||
x = time.Now()
|
x = time.Now()
|
||||||
im.logInstanceReport()
|
im.logInstanceReport()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user