feta/archiver.go

47 lines
903 B
Go
Raw Normal View History

2019-10-24 12:14:36 +00:00
package main
2019-11-02 06:56:17 +00:00
import "time"
2019-10-24 12:14:36 +00:00
2019-11-03 13:17:00 +00:00
type InstanceHostname string
2019-10-24 12:14:36 +00:00
2019-11-02 06:56:17 +00:00
type TootArchiver struct {
2019-11-03 13:17:00 +00:00
locator *InstanceLocator
manager *InstanceManager
startup *time.Time
2019-10-24 12:14:36 +00:00
}
2019-11-02 06:56:17 +00:00
func NewTootArchiver() *TootArchiver {
a := new(TootArchiver)
2019-10-24 12:14:36 +00:00
return a
}
2019-11-02 06:56:17 +00:00
func (a *TootArchiver) Uptime() time.Duration {
2019-10-24 12:41:05 +00:00
return time.Since(*a.startup)
}
2019-10-24 12:14:36 +00:00
2019-11-03 13:17:00 +00:00
func (a *TootArchiver) RunForever() {
2019-10-24 12:41:05 +00:00
t := time.Now()
a.startup = &t
2019-11-03 13:17:00 +00:00
2019-11-04 17:07:04 +00:00
newInstanceHostnameNotifications := make(chan InstanceHostname, 10000)
2019-11-03 13:17:00 +00:00
2019-10-24 12:41:05 +00:00
a.locator = NewInstanceLocator()
2019-11-03 13:17:00 +00:00
a.manager = NewInstanceManager()
a.locator.AddInstanceNotificationChannel(newInstanceHostnameNotifications)
a.manager.AddInstanceNotificationChannel(newInstanceHostnameNotifications)
// locator goroutine:
go a.locator.Locate()
2019-11-03 13:17:00 +00:00
// manager goroutine:
go a.manager.Manage()
// this goroutine (main) does nothing until we handle signals
// FIXME(sneak)
for {
time.Sleep(1 * time.Second)
}
2019-10-24 12:14:36 +00:00
}