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)
|
dh := NewDropletHandler(settings)
|
||||||
|
sm := NewServerManager("minecraft", dh, settings)
|
||||||
|
go sm.Serve()
|
||||||
|
|
||||||
ip, err := dh.Spinup("minecraft")
|
sm.Spinup()
|
||||||
if err != nil {
|
sm.Spindown()
|
||||||
log.Println("Error:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Println("IP: " + ip)
|
|
||||||
|
|
||||||
if err := dh.Spindown("minecraft"); err != nil {
|
sm.Stop()
|
||||||
log.Println("Error:", err)
|
sm.Done()
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ type ServerManager struct {
|
|||||||
name string
|
name string
|
||||||
ports []int
|
ports []int
|
||||||
in chan int
|
in chan int
|
||||||
out chan int
|
done chan interface{}
|
||||||
usageScore int // spin down server when this reaches 0
|
usageScore int // spin down server when this reaches 0
|
||||||
server ServerHandler
|
server ServerHandler
|
||||||
}
|
}
|
||||||
@ -27,8 +27,9 @@ type ServerManager struct {
|
|||||||
func NewServerManager(name string, server ServerHandler, settings Settings) *ServerManager {
|
func NewServerManager(name string, server ServerHandler, settings Settings) *ServerManager {
|
||||||
sm := new(ServerManager)
|
sm := new(ServerManager)
|
||||||
|
|
||||||
|
sm.name = name
|
||||||
sm.in = make(chan int)
|
sm.in = make(chan int)
|
||||||
sm.out = make(chan int)
|
sm.done = make(chan interface{})
|
||||||
sm.usageScore = 5
|
sm.usageScore = 5
|
||||||
sm.server = server
|
sm.server = server
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ func (me *ServerManager) Serve() {
|
|||||||
running = me.serveAction(action)
|
running = me.serveAction(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
me.done <- 42
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -75,6 +77,10 @@ func (me *ServerManager) Stop() {
|
|||||||
me.in <- SERVERMANAGER_STOP
|
me.in <- SERVERMANAGER_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *ServerManager) Done() {
|
||||||
|
<-me.done
|
||||||
|
}
|
||||||
|
|
||||||
func (me *ServerManager) addPortForwards(ip string) {
|
func (me *ServerManager) addPortForwards(ip string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +93,7 @@ func (me *ServerManager) serveAction(action int) bool {
|
|||||||
case SERVERMANAGER_SPINUP:
|
case SERVERMANAGER_SPINUP:
|
||||||
ip, err := me.server.Spinup(me.name)
|
ip, err := me.server.Spinup(me.name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
log.Println("ServerManager: Got IP for", me.name, ":", ip)
|
||||||
me.addPortForwards(ip)
|
me.addPortForwards(ip)
|
||||||
} else {
|
} else {
|
||||||
log.Println("ServerManager: Could not spin up "+me.name+":", err)
|
log.Println("ServerManager: Could not spin up "+me.name+":", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user