Switched test code over to using ServerManager. Fixed some bugs found testing ServerManager.
This commit is contained in:
parent
27a36e9380
commit
89a9b98b35
16
dospin.go
16
dospin.go
@ -32,16 +32,12 @@ func main() {
|
||||
}
|
||||
|
||||
dh := NewDropletHandler(settings)
|
||||
sm := NewServerManager("minecraft", dh, settings)
|
||||
go sm.Serve()
|
||||
|
||||
ip, err := dh.Spinup("minecraft")
|
||||
if err != nil {
|
||||
log.Println("Error:", err)
|
||||
return
|
||||
}
|
||||
log.Println("IP: " + ip)
|
||||
sm.Spinup()
|
||||
sm.Spindown()
|
||||
|
||||
if err := dh.Spindown("minecraft"); err != nil {
|
||||
log.Println("Error:", err)
|
||||
return
|
||||
}
|
||||
sm.Stop()
|
||||
sm.Done()
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ type ServerManager struct {
|
||||
name string
|
||||
ports []int
|
||||
in chan int
|
||||
out chan int
|
||||
done chan interface{}
|
||||
usageScore int // spin down server when this reaches 0
|
||||
server ServerHandler
|
||||
}
|
||||
@ -27,8 +27,9 @@ type ServerManager struct {
|
||||
func NewServerManager(name string, server ServerHandler, settings Settings) *ServerManager {
|
||||
sm := new(ServerManager)
|
||||
|
||||
sm.name = name
|
||||
sm.in = make(chan int)
|
||||
sm.out = make(chan int)
|
||||
sm.done = make(chan interface{})
|
||||
sm.usageScore = 5
|
||||
sm.server = server
|
||||
|
||||
@ -52,6 +53,7 @@ func (me *ServerManager) Serve() {
|
||||
running = me.serveAction(action)
|
||||
}
|
||||
}
|
||||
me.done <- 42
|
||||
}
|
||||
|
||||
/*
|
||||
@ -75,6 +77,10 @@ func (me *ServerManager) Stop() {
|
||||
me.in <- SERVERMANAGER_STOP
|
||||
}
|
||||
|
||||
func (me *ServerManager) Done() {
|
||||
<-me.done
|
||||
}
|
||||
|
||||
func (me *ServerManager) addPortForwards(ip string) {
|
||||
}
|
||||
|
||||
@ -87,6 +93,7 @@ func (me *ServerManager) serveAction(action int) bool {
|
||||
case SERVERMANAGER_SPINUP:
|
||||
ip, err := me.server.Spinup(me.name)
|
||||
if err == nil {
|
||||
log.Println("ServerManager: Got IP for", me.name, ":", ip)
|
||||
me.addPortForwards(ip)
|
||||
} else {
|
||||
log.Println("ServerManager: Could not spin up "+me.name+":", err)
|
||||
|
Loading…
Reference in New Issue
Block a user