working toward storing state in db
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
package manager
|
||||
|
||||
import "sync"
|
||||
import "time"
|
||||
import "runtime"
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.eeqj.de/sneak/feta/instance"
|
||||
"git.eeqj.de/sneak/feta/seeds"
|
||||
"git.eeqj.de/sneak/feta/toot"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
//import "github.com/gin-gonic/gin"
|
||||
import "github.com/rs/zerolog/log"
|
||||
import "git.eeqj.de/sneak/feta/toot"
|
||||
import "git.eeqj.de/sneak/feta/seeds"
|
||||
import "git.eeqj.de/sneak/feta/instance"
|
||||
|
||||
const hostDiscoveryParallelism = 5
|
||||
|
||||
// LogReportInterval defines how long between logging internal
|
||||
// stats/reporting for user supervision
|
||||
@@ -24,13 +25,15 @@ type InstanceManager struct {
|
||||
newInstanceNotifications chan instance.Hostname
|
||||
tootDestination chan *toot.Toot
|
||||
startup time.Time
|
||||
hostDiscoveryParallelism int
|
||||
hostAdderSemaphore chan bool
|
||||
}
|
||||
|
||||
// New returns a new InstanceManager for use by the Process
|
||||
func New() *InstanceManager {
|
||||
i := new(InstanceManager)
|
||||
i.hostAdderSemaphore = make(chan bool, hostDiscoveryParallelism)
|
||||
i.hostDiscoveryParallelism = viper.GetInt("HostDiscoveryParallelism")
|
||||
i.hostAdderSemaphore = make(chan bool, i.hostDiscoveryParallelism)
|
||||
i.instances = make(map[instance.Hostname]*instance.Instance)
|
||||
return i
|
||||
}
|
||||
@@ -41,30 +44,6 @@ func (im *InstanceManager) SetTootDestination(td chan *toot.Toot) {
|
||||
im.tootDestination = td
|
||||
}
|
||||
|
||||
func (im *InstanceManager) logCaller(msg string) {
|
||||
fpcs := make([]uintptr, 1)
|
||||
// Skip 2 levels to get the caller
|
||||
n := runtime.Callers(3, fpcs)
|
||||
if n == 0 {
|
||||
log.Debug().Msg("MSG: NO CALLER")
|
||||
}
|
||||
|
||||
caller := runtime.FuncForPC(fpcs[0] - 1)
|
||||
if caller == nil {
|
||||
log.Debug().Msg("MSG CALLER WAS NIL")
|
||||
}
|
||||
|
||||
// Print the file name and line number
|
||||
filename, line := caller.FileLine(fpcs[0] - 1)
|
||||
function := caller.Name()
|
||||
|
||||
log.Debug().
|
||||
Str("filename", filename).
|
||||
Int("linenum", line).
|
||||
Str("function", function).
|
||||
Msg(msg)
|
||||
}
|
||||
|
||||
func (im *InstanceManager) lock() {
|
||||
im.mu.Lock()
|
||||
}
|
||||
@@ -198,6 +177,7 @@ func (im *InstanceManager) logInstanceReport() {
|
||||
// ListInstances dumps a slice of all Instances the InstanceManager knows
|
||||
// about
|
||||
func (im *InstanceManager) ListInstances() []*instance.Instance {
|
||||
// FIXME make this pull from db
|
||||
var out []*instance.Instance
|
||||
im.lock()
|
||||
defer im.unlock()
|
||||
@@ -208,6 +188,7 @@ func (im *InstanceManager) ListInstances() []*instance.Instance {
|
||||
}
|
||||
|
||||
func (im *InstanceManager) instanceSummaryReport() map[string]uint {
|
||||
// FIXME make this pull from db
|
||||
r := make(map[string]uint)
|
||||
for _, v := range im.ListInstances() {
|
||||
v.Lock()
|
||||
|
||||
Reference in New Issue
Block a user